Home » SQL & PL/SQL » SQL & PL/SQL » what is the problem in this code??? and TRIGGER help (merged threads)
icon8.gif  what is the problem in this code??? and TRIGGER help (merged threads) [message #133910] Mon, 22 August 2005 14:03 Go to next message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
The job of this code is if any user delete anything in the tabe will save his information>>
Where is the probelm in this code . Could anyone help me please ??

CREATE TABLE ACTION_LOG (
USER_ID INTEGER,
USER_NAME VARCHAR2(30),
ACTION VARCHAR2(30),
ACTION_DATE DATE,
SES_USERNAME VARCHAR2(30),
SES_OSUSER VARCHAR2(30),
SES_MACHINE VARCHAR2(64),
SES_TERMINAL VARCHAR2(30),
SES_PROGRAM VARCHAR2(48),
SES_CLIENT_INFO VARCHAR2(64)
);



CREATE OR REPLACE TRIGGER TRG_ABC_USER_ACTION
BEFORE INSERT OR UPDATE OR DELETE
ON ABC_USER FOR EACH ROW
DECLARE
L_ACTION ACTION_LOG.ACTION%TYPE;
BEGIN
IF ( DELETING ) THEN L_ACTION := 'DELETE'; END IF;
INSERT INTO ACTION_LOG
SELECT :OLD.USER_ID, :OLD.USER_NAME, L_ACTION,
SYSDATE, S.USERNAME, S.OSUSER, S.MACHINE,
S.TERMINAL, S.PROGRAM, S.CLIENT_INFO
FROM V$SESSION S
WHERE S.AUDSID = USERENV('SESSIONID');
END;
/
Re: what is the problem in this code??? [message #133912 is a reply to message #133910] Mon, 22 August 2005 14:12 Go to previous messageGo to next message
mchadder
Messages: 224
Registered: May 2005
Location: UK
Senior Member
Hello.

Well, since you didn't post what the actual error was, or enough CREATE TABLEs in order to replicate properly, first thing was to create a table called ABC_USER, i.e.
SQL> CREATE TABLE abc_user ( user_id   VARCHAR2(30), user_name  VARCHAR2(30) );

Table created.

SQL> CREATE OR REPLACE TRIGGER TRG_ABC_USER_ACTION
  2  BEFORE INSERT OR UPDATE OR DELETE
  3  ON ABC_USER FOR EACH ROW
  4  
  5  DECLARE
  6  L_ACTION ACTION_LOG.ACTION%TYPE;
  7  BEGIN
  8  IF ( DELETING ) THEN L_ACTION := 'DELETE'; END IF;
  9  INSERT INTO ACTION_LOG
 10  SELECT :OLD.USER_ID, :OLD.USER_NAME, L_ACTION,
 11  SYSDATE, S.USERNAME, S.OSUSER, S.MACHINE,
 12  S.TERMINAL, S.PROGRAM, S.CLIENT_INFO
 13  FROM V$SESSION S
 14  WHERE S.AUDSID = USERENV('SESSIONID');
 15  END;
 16  /

Warning: Trigger created with compilation errors.

SQL> SHO ERR
Errors for TRIGGER TRG_ABC_USER_ACTION:

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1      PL/SQL: SQL Statement ignored
9/6      PL/SQL: ORA-00942: table or view does not exist

Next problem was that my current user didn't have select access on v_$session directly, so :
SQL> grant SELECT ON V_$SESSION TO MCHADDER;

Grant succeeded.

Then recreating the trigger is successful :
SQL> CREATE OR REPLACE TRIGGER TRG_ABC_USER_ACTION
  2  BEFORE INSERT OR UPDATE OR DELETE
  3  ON ABC_USER FOR EACH ROW
  4  
  5  DECLARE
  6  L_ACTION ACTION_LOG.ACTION%TYPE;
  7  BEGIN
  8  IF ( DELETING ) THEN L_ACTION := 'DELETE'; END IF;
  9  INSERT INTO ACTION_LOG
 10  SELECT :OLD.USER_ID, :OLD.USER_NAME, L_ACTION,
 11  SYSDATE, S.USERNAME, S.OSUSER, S.MACHINE,
 12  S.TERMINAL, S.PROGRAM, S.CLIENT_INFO
 13  FROM V$SESSION S
 14  WHERE S.AUDSID = USERENV('SESSIONID');
 15  END;
 16  /

Trigger created.

Rgds
Re: what is the problem in this code??? [message #133914 is a reply to message #133912] Mon, 22 August 2005 14:24 Go to previous messageGo to next message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
Cool thank you ..
Re: what is the problem in this code??? [message #134016 is a reply to message #133914] Tue, 23 August 2005 05:23 Go to previous messageGo to next message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
I am getting this error .
see the code

SQL> CREATE TABLE ACTION_LOG (
2 USER_ID INTEGER,
3 USER_NAME VARCHAR2(100),
4 ACTION VARCHAR2(100),
5 ACTION_DATE DATE,
6 SES_USERNAME VARCHAR2(100),
7 SES_OSUSER VARCHAR2(100),
8 SES_MACHINE VARCHAR2(100),
9 SES_TERMINAL VARCHAR2(100),
10 SES_PROGRAM VARCHAR2(100),
11 SES_CLIENT_INFO VARCHAR2(100)
12 );

Table created.

SQL> CREATE OR REPLACE TRIGGER TRG_ABC_USER_ACTION
2 BEFORE INSERT OR UPDATE OR DELETE
3 ON counter2005 FOR EACH ROW
4 
4 DECLARE
5 L_ACTION ACTION_LOG.ACTION%TYPE;
6 BEGIN
7 IF ( DELETING ) THEN L_ACTION := 'DELETE'; END IF;
8 INSERT INTO ACTION_LOG
9 SELECT :OLD.USER_ID, :OLD.USER_NAME, L_ACTION,
10 SYSDATE, S.USERNAME, S.OSUSER, S.MACHINE,
11 S.TERMINAL, S.PROGRAM, S.CLIENT_INFO
12 FROM V$SESSION S
13 WHERE S.AUDSID = USERENV('SESSIONID');
14 END;
15 /

Warning: Trigger created with compilation errors.

SQL> sho err
buffer overflow. Use SET command to reduce ARRAYSIZE or increase MAXDATA.
No errors.
SQL> remark ----> The current user have select access on V$SESSION
Re: what is the problem in this code??? [message #134029 is a reply to message #133910] Tue, 23 August 2005 06:27 Go to previous messageGo to next message
mchadder
Messages: 224
Registered: May 2005
Location: UK
Senior Member
Hello.

well, the goalposts have changed again.... Wink

Anyway, remember that you need DIRECT select access on v_$session, (not v$session which is a public synonym), also (given I can't see the error that's being generated), what's the definition of
"counter2005"?

Rgds
Re: what is the problem in this code??? [message #134059 is a reply to message #134029] Tue, 23 August 2005 07:58 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
And on a related ntoe, set arraysize 1 will solve the problem of being bale to see your error
Re: what is the problem in this code??? [message #134372 is a reply to message #134059] Wed, 24 August 2005 09:54 Go to previous messageGo to next message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
I really don't know what to do ??? Mad
What actually I want is ,to make the user not be able to delete any thing from the sex tables.( Tables which installed with oracle)
I wrote this code
CREATE OR REPLACE TRIGGER DEL_TEST
BEFORE DELETE ON counter2005
 BEGIN
 RAISE_APPLICATION_ERROR(-20500,'cAN nOT dELETE.');
 END;

I tried to delete any thing from the table , I got this
ERROR at line 1:
ORA-20500: cAN nOT dELETE.
ORA-06512: at "SHIFA.DEL_TEST", line 2
ORA-04088: error during execution of trigger 'SHIFA.DEL_TEST'

But after some time it delete all the sex tables .
Who it is happened ???
I don't know ??
please help me
Re: what is the problem in this code??? [message #134411 is a reply to message #134372] Wed, 24 August 2005 15:53 Go to previous messageGo to next message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
UP
TRIGGER help [message #134635 is a reply to message #133910] Thu, 25 August 2005 19:11 Go to previous messageGo to next message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
I really don't know what to do ???
What actually I want is ,to make the user not be able to delete any thing from the sex tables.( Tables which installed with oracle)
I wrote this code
CREATE OR REPLACE TRIGGER DEL_TEST
BEFORE DELETE ON counter2005
 BEGIN
 RAISE_APPLICATION_ERROR(-20500,'cAN nOT dELETE.');
 END;

I tried to delete any thing from the table , I got this
ERROR at line 1:
ORA-20500: cAN nOT dELETE.
ORA-06512: at "SHIFA.DEL_TEST", line 2
ORA-04088: error during execution of trigger 'SHIFA.DEL_TEST'

But after some time it delete all the sex tables .
Who it is happened ???
I don't know ??
please help me
Re: TRIGGER help [message #134741 is a reply to message #134635] Fri, 26 August 2005 10:26 Go to previous message
Ansi
Messages: 19
Registered: August 2005
Location: India
Junior Member
up
Previous Topic: new title
Next Topic: Urgent help-Delete large number of rows
Goto Forum:
  


Current Time: Sun Jun 02 20:55:53 CDT 2024