1

I wrote a trigger in which I have a line:

SELECT * 
  INTO :NEW.EVENTDATE 
  FROM (SELECT SYSDATE 
          FROM DUAL);

For some reason this does not work (EVENTDATE column has timestamp(0) type).

When I try to insert something I get error message saying that value is too long for that column. I though SYSDATE and timestamp(0) would coalesce and understand each other.

What the ?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Nickolodeon
  • 2,848
  • 3
  • 23
  • 38
  • 1
    Can you post the actual DDL of your table? The error you are getting strongly implies that EventDate is declared as a VARCHAR2, not as a TIMESTAMP. – Justin Cave Feb 02 '11 at 22:06
  • 1
    Or that the problem is not in the trigger but in the actual INSERT statement. – Justin Cave Feb 02 '11 at 22:21

5 Answers5

2

You should just do this in PL/SQL

:new.EventDate := SYSTIMESTAMP;

but if you want to use SQL

SELECT systimestamp
  INTO :new.EventDate
  FROM dual;
Justin Cave
  • 227,342
  • 24
  • 367
  • 384
1

Try an explicit cast such as

select cast(sysdate as timestamp(0)) from dual

As a thought, is there anything exotic with your session's calendar settings which might force a unusual conversion. If so, try specifying the appropriate calendar in a conversion.

select to_char(sysdate,'DD-fmMonth-YYYY','nls_calendar=''Arabic Hijrah''') from dual;
Gary Myers
  • 34,963
  • 3
  • 49
  • 74
0

I don't know why this wouldn't work. Can you post the actual error (with code and everything) that you are getting?

I also don't know why you wouldn't just assign the variable:

:NEW.EVENTDATE := systimestamp;
Craig
  • 5,740
  • 21
  • 30
0

What version are you running?

The following works fine on Oracle 11R2:

drop   table tq84_eventdate;

create table tq84_eventdate (
  data      varchar2(10),
  eventdate timestamp(0)
);

create trigger tq84_eventdate_trg 
before insert on tq84_eventdate 
for each row
begin

  SELECT * INTO :NEW.EVENTDATE FROM (SELECT SYSDATE FROM DUAL);

end tq84_eventdate_trg;
/


insert into tq84_eventdate (data) values ('test');

select * from tq84_eventdate;

However, if I do a

insert into tq84_eventdate (data) values ('value too large!');

I get the ORA-12899 you mentioned. So, the error is probably not related to the select statement you posted, but to the data that you actually try to insert.

Also, on a related note, you can assign sysdate directly in the trigger, that is without the indirection of a select statement:

create trigger tq84_eventdate_trg 
before insert on tq84_eventdate 
for each row
begin

  :new.eventdate := sysdate;

end tq84_eventdate_trg;
/
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
  • I'm using 10g. I can't seem to find a way modify Width property of that column. It is 7 and that is all to it( I need 11, according to exception – Nickolodeon Feb 02 '11 at 21:47
  • I don't believe you don't neet 10g. Rather, you need to reduce the length of another value you try to insert. – René Nyffenegger Feb 02 '11 at 21:49
0

I was able to exhort my bosses to convert one column's type to another. Namely timestamp to DATE.

Strangely enough nobody throughout this branch has not pointed out that I could substitute Timestamp field with DATE field.

Nickolodeon
  • 2,848
  • 3
  • 23
  • 38