Issue with Trigger [message #353228] |
Mon, 13 October 2008 00:58 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Guru's,
I need some help to make the Trigger working. If there is any changes (Insert or Update) on the table TEST1, I need to update the coloumn DFIELD of table DATE2. The below trigger does not give me any error but does not update the field DFIELD in table DATE2.
create or replace trigger XYZ
after insert or update on TEST1
begin
update DATE2
SET DFIELD =sysdate;
end XYZ;
This works fine
I have changed the trigger as below with using newRow. But this one gives me below error.
create or replace trigger XYZ
after insert on TEST1
REFERENCING NEW AS newRow
for each row
begin
update DATE2
SET DFIELD =:newRow.sysdate;
end XYZ;
Line # = 3 Column # = 18 Error Text = PLS-00049: bad bind variable 'NEWROW.SYSDATE'
Please help me as I had got help from this site before in past.
Thank in advance.
syd
|
|
|
Re: Issue with Trigger [message #353231 is a reply to message #353228] |
Mon, 13 October 2008 01:06 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
sysdate is not a field of newrow record.
Why did you change your previous working trigger?
In addition:
1/ The trigger update the whole table, is this you really want
2/ Don't do this in trigger, use a procedure to clearly update the 2 tables.
Regards
Michel
[Updated on: Mon, 13 October 2008 01:06] Report message to a moderator
|
|
|
Re: Issue with Trigger [message #353236 is a reply to message #353228] |
Mon, 13 October 2008 01:18 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Michel,
Thanks for your reply. OK I will concentrate on the first trigger and discuss that only in my correspondence.
The problem I am having is when i update the table 'TEST1' the coloumn DFIELD i table DATE2 has not been updated. Please advice.
Rgds
Syd
|
|
|
|
Re: Issue with Trigger [message #353240 is a reply to message #353228] |
Mon, 13 October 2008 01:25 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Dr Raghu,
Please find below the information you has requested.
SQL> desc TEST1
Name Null? Type
----------------------------------------- -------- ----------------------------
USERNAME NOT NULL VARCHAR2(20)
USERID NOT NULL VARCHAR2(20)
DATEFIELD DATE
SQL> desc DATE2
Name Null? Type
----------------------------------------- -------- ----------------------------
DFIELD NOT NULL DATE
USERID VARCHAR2(20)
SQL>
Thanks for help
Syd
|
|
|
Re: Issue with Trigger [message #353241 is a reply to message #353240] |
Mon, 13 October 2008 01:29 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
for your Convenience
SQL> desc TEST1
Name Null? Type
----------------------------------------- -------- ----------------------------
USERNAME NOT NULL VARCHAR2(20)
USERID NOT NULL VARCHAR2(20)
DATEFIELD DATE
SQL> desc DATE2
Name Null? Type
----------------------------------------- -------- ----------------------------
DFIELD NOT NULL DATE
USERID VARCHAR2(20)
SQL>
Syd
|
|
|
|
|
Re: Issue with Trigger [message #353245 is a reply to message #353240] |
Mon, 13 October 2008 01:34 |
dr.s.raghunathan
Messages: 540 Registered: February 2008
|
Senior Member |
|
|
hi,
hope your userid in test1 is unique.
update date2 set dfield = (write the select statement using userid of test1). complete it you will be successful.
yours
dr.s.raghunathan
|
|
|
Re: Issue with Trigger [message #353254 is a reply to message #353245] |
Mon, 13 October 2008 01:46 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Dr Raghu, Rajuvan and Mitch.
Thanks for helping me around.
Raghu I have chaned trigger have a look, Still the table DATE2 is not been updated.
SQL> create or replace trigger trg_mv_dept
2 after insert or update on LDAPTEST
3 for each row
4 begin
5 update INSERTLDAPDATE
6 SET DATEFIELD =sysdate
7 WHERE USERID = :NEW.USERID;
8 END;
9 /
Trigger created.
Raju,
I am using OEM to insert the row and see it has been added. next time I will add using script and update you too.
Is there is any template of procedure to do as I want to achive.
Thanks again
Syd
|
|
|
Re: Issue with Trigger [message #353255 is a reply to message #353228] |
Mon, 13 October 2008 01:50 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Rajuvan,
INSERT INTO "SCOTT"."TEST1" ("USERNAME" ,"USERID" ,"DATEFIELD"
)
VALUES
('nick' ,'13' ,TO_DATE('', 'dd-Mon-yyyy HH:MI:SS AM')
);
commit;
Rgds
SYD
|
|
|
Re: Issue with Trigger [message #353256 is a reply to message #353254] |
Mon, 13 October 2008 01:50 |
dr.s.raghunathan
Messages: 540 Registered: February 2008
|
Senior Member |
|
|
hi,
now i am confused with your sysdate concept. I thought whenever you are inserting test1 with userid and datefield, the date available in datefeild should be get updated in date2(dfield).
since you have used statement trigger with after.
yours
dr.s.raghunathan
|
|
|
|
|
|
|
Re: Issue with Trigger [message #353437 is a reply to message #353228] |
Mon, 13 October 2008 22:22 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Thanks to all of you for help and suggestions.
I have changed the trigger to before insert trigger and on the same table as below and it is working fine.
create or replace trigger XYZ
before insert or update on TEST
for each row
begin
:NEW.DFIELD := sysdate;
end ;
Keep helping each other guys. Good on all our DBA's community.
SYD
|
|
|
|
Re: Issue with Trigger [message #353442 is a reply to message #353228] |
Mon, 13 October 2008 22:35 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Thanks Rajuvan,
Actually I can't make after trigger working as it is not taking :new.sysdate.
what i want to achive is whenever anything update or insert happens on the table TEST. DFIELD should be updated with 'sysdate'.
BUt I think if I make after trigger working that is better. As the DFILED should be updated after any changes in other fields.
But I can't make after trigger work.
if you have any suggestion to fix after trigger. Please advice.
Regards
SYD
|
|
|
|
Re: Issue with Trigger [message #353450 is a reply to message #353228] |
Mon, 13 October 2008 22:55 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Rajuvan,
when i use after trigger I am getting the below error.
SQL> create or replace trigger XYZ
2 after insert or update on TEST
3 for each row
4 begin
5 :NEW.DFIELD := sysdate;
6 end;
7 /
create or replace trigger test
*
ERROR at line 1:
ORA-04084: cannot change NEW values for this trigger type
I have searched the google and found
ORA-04084: cannot change NEW values for this trigger type
Cause: New trigger variables can only be changed in before row insert or update triggers.
Action: Change the trigger type or remove the variable reference.
rgds
SYD
|
|
|
|
Re: Issue with Trigger [message #353463 is a reply to message #353228] |
Tue, 14 October 2008 00:04 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Rajuvan,
You are right that code will work. But now I have to add a column in the same table and update that column that is the reason I am using another trigger.
Thanks for your help.
Rgds
SYD
|
|
|
|
Re: Issue with Trigger [message #353500 is a reply to message #353228] |
Tue, 14 October 2008 01:03 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi Kevin,
Thanks for nice explanation. Appreciate your help. Yes I have written before trigger and it works. If I find time I will do the test per your and Rajuvan suggest and update you guys.
Thanks
Rgds
Syd
|
|
|
|
Re: Issue with Trigger [message #353979 is a reply to message #353228] |
Thu, 16 October 2008 00:03 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Hi All the one who helped me.
I am using sysdate in my trigger to compare the date/time.
but when i query sysdate in sqlplus its not giving me time as below.
SQL> select sysdate from dual;
SYSDATE
---------
16-OCT-08
SQL> select TO_CHAR(sysdate,'DD-Mon-YYYY HH24:MI:SS') FROM dual;
TO_CHAR(SYSDATE,'DD-
--------------------
16-Oct-2008 15:58:53
In the script I have written in perl is using sysdate to distinguish between the two times.
I want to use only sysdate to give me day and time.
the column datatype is DATE.
Please advice.
SYD
|
|
|
|
Re: Issue with Trigger [message #353990 is a reply to message #353228] |
Thu, 16 October 2008 00:47 |
sydney1
Messages: 65 Registered: November 2006 Location: sydney
|
Member |
|
|
Thanks again Rajuvan,
I am working on the issue to syncronize the table with Active Directory.
The script is running to syncronize the AD with table every 15 minutes.
I am bit confused how to write the code.
the code should be like
select * from table
where timemodified > 'here the time of the script as we want to run the script every 15 minutes' if the script runs at 1am then again at 1.15am and check the table coloumn.
Please help if someone done like this.
Thank in advance
SYD
|
|
|