PLS-00049: bad bind variable 'NEW.NEW_SKILL_DESC' - oracle

When I run the trigger the PLS-00049: bad bind variable 'NEW.NEW_SKILL_DESC' problems occur. The problem occurs in the: New section. This is the first time I am auditing a database query.
CREATE OR REPLACE TRIGGER lds_skill_trig
BEFORE INSERT OR DELETE OR UPDATE ON LDS_SKILL
FOR EACH ROW
ENABLE
DECLARE
v_user VARCHAR2(30);
v_date VARCHAR2(30);
BEGIN
SELECT user, TO_CHAR(sysdate, 'DD/M0N/YYYY HH24:MI:SS')
INTO v_user, v_date FROM dual;
IF INSERTING THEN
INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc,user_name,
entry_date, operation)
VALUES(:NEW.new_skill_desc, NULL, v_user, v_date, 'Insert');
ELSIF DELETING THEN
INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name,
entry_date, operation)
VALUES(NULL, :OLD.new_skill_desc, v_user, v_date, 'Delete');
ELSIF UPDATING THEN
INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name,
entry_date, operation)
VALUES(:NEW.new_skill_desc, :OLD.new_skill_desc, v_user, v_date,'update');
END IF;
END;
This is the table for db_lds_skill where the audit record i want to save.
CREATE TABLE DB_LDS_SKILL
(NEW_SKILL_DESC VARCHAR2(30),
OLD_SKILL_DESC VARCHAR2(30),
USER_NAME VARCHAR2(30),
ENTRY_DATE VARCHAR2(30),
OPERATION VARCHAR2(30)
);

It seems you are adding wrong column name in the :NEW.new_skill_desc, in The :new. you have to specific the column for the table LDS_SKILL table, not db_lds_skill
The below I created locally and it was working fine, Note that I replaced to_date with to_char and replaced M0N with MON
drop table db_lds_skill
/
create table db_lds_skill
(new_skill_desc varchar2(100) null,
old_skill_desc varchar2(100) null,
user_name varchar2(100) null,
entry_date varchar2(100),
operation varchar2(100) null
)
/
drop table LDS_SKILL
/
create table LDS_SKILL
(new_skill_desc varchar2(100) null,
old_skill_desc varchar2(100) null,
user_name varchar2(100) null,
entry_date varchar2(100) nulll,
operation varchar2(100) null
)
/
CREATE OR REPLACE TRIGGER lds_skill_trig
BEFORE INSERT OR DELETE OR UPDATE ON LDS_SKILL
FOR EACH ROW
ENABLE
DECLARE
v_user VARCHAR2(30);
v_date VARCHAR2(30);
BEGIN
SELECT user, TO_CHAR(sysdate, 'DD/MON/YYYY HH24:MI:SS')
INTO v_user, v_date FROM dual;
IF INSERTING THEN
INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc,user_name,
entry_date, operation)
VALUES(:NEW.new_skill_desc, NULL, v_user, v_date, 'Insert');
ELSIF DELETING THEN
INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name,
entry_date, operation)
VALUES(NULL, :OLD.new_skill_desc, v_user, v_date, 'Delete');
ELSIF UPDATING THEN
INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name,
entry_date, operation)
VALUES(:NEW.new_skill_desc, :OLD.new_skill_desc, v_user, v_date,'update');
END IF;
END;
/
insert into LDS_SKILL (new_skill_desc) values('pp')
/
commit
/

Related

Need to accept comma separated inputs from the stored procedure and have to process as I have explained in the below body but getting compilation err

CREATE TABLE STAGING
(
E_ID NUMBER(10),
E_NAME VARCHAR2(30),
E_LOC VARCHAR2(30),
VALIDATION_STATUS varchar2(30),
validation_msg varchar2(30),
req_id number(10)
);
INSERT INTO staging VALUES(1, 'A', 'AA', NULL, NULL, 1);
INSERT INTO staging VALUES(2, 'B', 'BB', NULL, NULL, 1);
INSERT INTO staging VALUES(3, 'C', 'CC', NULL, NULL, 1);
INSERT INTO staging VALUES(NULL, 'D', 'DD', NULL, NULL, 2);
INSERT INTO staging VALUES(NULL, 'E', 'EE', NULL, NULL, 2);
INSERT INTO staging VALUES(NULL, 'F', 'GG', NULL, NULL, 2);
CREATE TABLE tab_ref
(
ref_id number(10),
ref_name varchar2(30)
);
INSERT INTO tab_ref VALUES(1, 'aa');
INSERT INTO tab_ref VALUES(2, 'bb');
INSERT INTO tab_ref VALUES(3, 'cc');
INSERT INTO tab_ref VALUES(4, 'dd');
CREATE TABLE tab_ref_2
(
ref_id number(10),
ref_name varchar2(30)
);
INSERT INTO tab_ref_2 VALUES(1, 'ee');
INSERT INTO tab_ref_2 VALUES(2, 'ff');
INSERT INTO tab_ref_2 VALUES(3, 'gg');
INSERT INTO tab_ref_2 VALUES(4, 'hh');
CREATE TABLE SUMMARY_TAB
(
TOT_RECORDS NUMBER(10,0),
SUCCESS_RECORDS NUMBER(10,0),
FAILED_RECORDS NUMBER(10,0),
process_status varchar2(30)
);
CREATE TABLE TARGET_TAB
(
E_ID NUMBER(10,0),
E_NAME VARCHAR2(30),
E_LOC VARCHAR2(30)
);
Stored procedure:
create or replace procedure sp_stage_target(iv_req_id IN sys.OdciNumberList,ov_err_msg OUT varchar2) is
lv_succ_rec number(30);
lv_fail_rec number(30);
lv_count_ref number(10);
lv_count_ref2 number(10);
lv_threshold_cnt number(10);
lv_RejectedCount number(10);
lv_status varchar2(30);
begin
lv_succ_rec := 0;
lv_fail_rec := 0;
lv_threshold_cnt := 5;
/*First checking whether data is present in reference table or not.
If data is not present then process should stop*/
select count(1) into lv_count_ref from tab_ref;
select count(1) into lv_count_ref2 from tab_ref_2;
if lv_count_ref = 0 then
ov_err_msg := 'Records are not present in the reference table !!Cannot proceed';
elsif lv_count_ref2 = 0 then
ov_err_msg := 'Records are not present in the reference table !!Cannot proceed';
else
dbms_output.put_line('Data are present into reference tables');
merge into staging d
using (
select 'Fail' as validation_status, t.column_value as req_id
from table(iv_req_id) t
) s
on (d.req_id = s.req_id)
when matched then
update set
d.validation_status = s.validation_status
, d.validation_msg = case
when e_id is null then 'Id is not present'
else 'Id is longer than expected'
end
where e_id is null OR LENGTH(e_id) > 4;
lv_RejectedCount := SQL%ROWCOUNT;
end if;
--If rejected count is less than lv_threshold_cnt i.e 5
--then success records will go in target_tab and failed records will go in reject_tab
if lv_RejectedCount <= lv_threshold_cnt then
lv_status := 'Success';
dbms_output.put_line('Success');
merge into target_tab t
using (
select e_id, e_name, e_loc
from staging
where validation_status is null and req_id in (select column_value from table(iv_req_id))
) s
on (t.e_id = s.e_id)
when matched then
update set
t.e_name = s.e_name,
t.e_loc = s.e_loc
when not matched then
insert (t.e_id,t.e_name,t.e_loc)
values (s.e_id,s.e_name,s.e_loc);
lv_succ_rec := SQL%ROWCOUNT;
end if;
insert into reject_tab
select e_id, e_name, e_loc, validation_status,validation_msg
from staging
where validation_status = 'Fail' and req_id in (select column_value from table(iv_req_id));
lv_fail_rec := SQL%ROWCOUNT;
--In Summary table keeping track of all the records i.e success record, failed records
dbms_output.put_line('Inserting into Summary table');
insert into summary_tab(tot_records, success_records, failed_records, process_status)
values (lv_succ_rec + lv_fail_rec, lv_succ_rec, lv_fail_rec, lv_status);
ov_err_msg := 'Procedure completed succesfully';
end;
Calling Procedure:
set serveroutput on;
declare
err_msg;
begin
sp_main_target(sys.OdciNumberList(1,2),err_msg);
dbms_output.put_line(err_msg);
end;
Getting compilation error and also I am not not how to process for individually for each request_id and process so have highlighted the requirement in comment block.
Error :
I wanted to create a stored procedure that will handle all the below points and I have tried but not been able to get the results.
The stored procedure should accept multiple input parameters while calling a procedure and should process for every request-id given in the parameter with comma-separated.
Then stored procedure will check whether data is present or not in the ref table (tab_ref & tab_ref_2). If data is present then only the process should start otherwise it will not proceed further.
Then it will check the data in the staging table and will do validation for e_id is null or not or its length should not exceed the given limit. For every failed validation it will update the validation status and validation msg column and have to keep count of rejected columns.
After validation, if the threshold count is less then the lv_threshold_count then insertion will happen in both the tables with status as 'Success 'i.e target table and rejected table with validation_status as null and Fail respectively.
If threshold count is more than the lv_threshold_count then it will insert into the rejected table with status as 'Fail'.
Then at last it will show all the records count into the summary table.
You start an IF on line 20 of your procedure, but you don't have a corresponding END IF.
if lv_count_ref = 0 then

compiler error while creating trigger in sql developer; [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have two tables:
create table superheroes('sh_name varchar2(30));
create table sh_audit(new_name varchar2(30), old_name varchar2(30), username varchar2(30), entry_date varchar2(30), operation);
trigger:
create or replace trigger SUPERHEROES_AUDIT
before insert or update or delete on superheroes
for each row
enable
declare
v_user varchar2(30);
v_date varchar2(30);
begin
select user, TO_CHAR(SYSDATE,' DD/MM/YYYY HH24:MI:SS') INTO v_user, v_date from dual;
if inserting then
insert into sh_audit(new_name, old_name, username, entry_date, operation)
values(:NEW.sh_name, null, v_user, v_date,'insert');
elsif deleting then
insert into sh_audit(new_name, old_name, username, entry_date, operation)
values(null, :OLD.sh_name, v_user, v_date,'delete');
elsif updateing then
insert into sh_audit(new_name, old_name, username, entry_date, operation)
values(:NEW.sh_name, :OLD.sh_name, v_user, v_date,'update');
end if;
end;
/
error: Trigger SUPERHEROES_AUDIT compiled Errors: check compiler log
Error(5,5): PL/SQL: Statement ignored Error(11,11): PLS-00201:
identifier 'UPDATEING' must be declared.
try separating the trigger like this:
CREATE OR REPLACE TRIGGER TRG_BI_SUPERHEROES_AUDIT
BEFORE INSERT
ON SUPERHEROES
FOR EACH ROW
ENABLE
BEGIN
INSERT INTO SH_AUDIT (NEW_NAME, OLD_NAME, USERNAME, ENTRY_DATE, OPERATION)
VALUES (
:NEW.SH_NAME,
NULL,
USER,
TO_CHAR (SYSDATE, ' DD/MM/YYYY HH24:MI:SS'),
'insert');
END;
CREATE OR REPLACE TRIGGER TRG_BU_SUPERHEROES_AUDIT
BEFORE UPDATE
ON SUPERHEROES
FOR EACH ROW
ENABLE
BEGIN
INSERT INTO SH_AUDIT (NEW_NAME, OLD_NAME, USERNAME, ENTRY_DATE, OPERATION)
VALUES (
:NEW.SH_NAME,
:OLD.SH_NAME,
USER,
TO_CHAR (SYSDATE, ' DD/MM/YYYY HH24:MI:SS'),
'update');
END;
CREATE OR REPLACE TRIGGER TRG_BD_SUPERHEROES_AUDIT
BEFORE DELETE
ON SUPERHEROES
FOR EACH ROW
ENABLE
BEGIN
INSERT INTO SH_AUDIT (NEW_NAME, OLD_NAME, USERNAME, ENTRY_DATE, OPERATION)
VALUES (
NULL,
:OLD.SH_NAME,
USER,
TO_CHAR (SYSDATE, ' DD/MM/YYYY HH24:MI:SS'),
'insert');
END;

How to display time only

Can anyone help me how can I change the output of Time_done to a time only (example: 5:00AM)? If I add TO_CHAR(SYSDATE, 'HH24:MI:SS') on SYSDATE, I got an error message
ORA-01843: not a valid month.
Below are my codes and screen capture of EVENTLOGS table
CREATE TABLE EVENTLOGS(
Eventlog_id Number(3,0) NOT NULL,
User_name Varchar2(20),
Date_done Date,
Time_done Timestamp,
Action_done Varchar2(50),
CONSTRAINT PK_EVENTLOGS PRIMARY KEY (Eventlog_id));
/* TRIGGER CREATION */
CREATE OR REPLACE TRIGGER SUPERHEROES_AUDIT
AFTER INSERT OR DELETE OR UPDATE ON SUPERHEROES
FOR EACH ROW
ENABLE
DECLARE
V_LOGID NUMBER;
V_USER VARCHAR(30);
V_DATE DATE;
BEGIN
SELECT EVENTLOG_ID_SEQ.NEXTVAL, USER INTO V_LOGID, V_USER FROM DUAL;
IF INSERTING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Time_done, Action_done)
VALUES (V_LOGID, V_USER, SYSDATE, SYSDATE, 'INSERT');
ELSIF DELETING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Action_done)
VALUES (V_LOGID, V_USER, V_DATE, SYSDATE, SYSDATE, 'DELETE');
ELSIF UPDATING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Action_done)
VALUES (V_LOGID, V_USER, V_DATE, SYSDATE, SYSDATE, 'UPDATE');
END IF;
END;
/
[![INSERT INTO
EMPLOYEE_T (EmployeeID, EmployeeName, EmployeeAddress, EmployeeCity, EmployeeState, EmployeeZip, EmployeeBirthDate, EmployeeDateHired, EmployeeSupervisor)
VALUES (2, 'JACKIE', 'AFRICA', 'kenya', 'NO', 11285, TO_DATE('13-OCT-1950', 'DD-MM-YYYY'), TO_DATE('27-JUN-2014', 'DD-MM-YYYY'), 455789);][1]][1]
You have posted an incomplete TRIGGER code with too many errors.
If you are inserting data into a TIMESTAMP column, you need to insert a compatible record. Inserting only time portion is not useful as you cannot do direct date arithmetic / comparison operations which may be required on the column. I have used SYSTIMESTAMP function here to insert current system TIMESTAMP
CREATE OR REPLACE TRIGGER SUPERHEROES_AUDIT
AFTER INSERT OR DELETE OR UPDATE ON SUPERHEROES
FOR EACH ROW
ENABLE
DECLARE
V_LOGID NUMBER;
V_USER VARCHAR(30);
V_DATE DATE;
BEGIN
SELECT EVENTLOG_ID_SEQ.NEXTVAL, USER, SYSDATE INTO V_LOGID, V_USER, V_DATE FROM DUAL;
IF INSERTING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Time_done,Action_done)
VALUES (V_LOGID, V_USER, V_DATE, SYSTIMESTAMP, 'INSERT');
ELSIF DELETING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done,Time_done, Action_done)
VALUES (V_LOGID, V_USER, V_DATE, SYSTIMESTAMP, 'DELETE');
ELSIF UPDATING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done,Time_done, Action_done)
VALUES (V_LOGID, V_USER, V_DATE, SYSTIMESTAMP, 'UPDATE');
END IF;
END;
/
Here is the sample data
select * FROM EVENTLOGS;
EVENTLOG_ID USER_NAME DATE_DONE TIME_DONE ACTION_DONE
----------- -------------- --------- ------------------------------- ------------
1 SLDDEVELOPER 13-OCT-17 13-OCT-17 04.58.07.237343000 AM INSERT
If you need only time portion and not the DATE portion in your time_done column, then it should be a VARCHAR2 column and you can use TO_CHAR while inserting in this case as you were attempting to do.
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Time_done,Action_done)
VALUES (V_LOGID, V_USER, V_DATE, TO_CHAR(SYSDATE,'HH24:MI:SS'), 'INSERT');

SQL Error: ORA-01843: not a valid month

I am receiving ORA-01843 when I run the Insert command below. Is there something wrong with my code? And got the below error messages:
SQL Error:
ORA-01843: not a valid month
ORA-06512: at "MDSYS.SUPERHEROES_AUDIT", line 8
ORA-04088: error during execution of trigger 'MDSYS.SUPERHEROES_AUDIT'
01843. 00000 - "not a valid month"
What seems to be wrong with my declaration? Thank you.
/* TABLE CREATED */
CREATE TABLE EVENTLOGS(
Eventlog_id Number(3,0) NOT NULL,
User_name Varchar2(20),
Date_done Date,
Action_done Varchar2(50),
CONSTRAINT PK_EVENTLOGS PRIMARY KEY (Eventlog_id));
/* SEQUENCE CREATED */
CREATE SEQUENCE EVENTLOG_ID_SEQ
MINVALUE 1
START WITH 1
INCREMENT BY 1
NOCYCLE
CACHE 10;
/* TRIGGER CREATED */
CREATE OR REPLACE TRIGGER SUPERHEROES_AUDIT
AFTER INSERT OR DELETE OR UPDATE ON SUPERHEROES
FOR EACH ROW
ENABLE
DECLARE
V_LOGID NUMBER;
V_USER VARCHAR(30);
V_DATE VARCHAR(30);
BEGIN
SELECT EVENTLOG_ID_SEQ.NEXTVAL, USER, TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') INTO V_LOGID, V_USER, V_DATE FROM DUAL;
IF INSERTING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Action_done)
VALUES (V_LOGID, V_USER, V_DATE, 'INSERT');
END IF;
END;
/
INSERT INTO SUPERHEROES VALUES ('TEST');
Your column in the table is defined as
Date_done Date,
You are storing the date into a VARCHAR2 variable
V_DATE VARCHAR(30);
....
SELECT EVENTLOG_ID_SEQ.NEXTVAL, USER,
TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') INTO V_LOGID, V_USER, V_DATE
...
And you are inserting this variable into the DATE column.
...
VALUES (V_LOGID, V_USER, V_DATE, 'INSERT');
Keep datatype consistent to avoid confusion.

Oracle 11g cannot run trigger and insert records

While running this code I am getting Error message.
CREATE TABLE superheoes
(
sh_name VARCHAR2(20)
);
CREATE OR REPLACE TRIGGER superheroes_audit
BEFORE INSERT OR DELETE OR UPDATE ON superheoes
FOR EACH ROW
ENABLE
DECLARE
v_user VARCHAR2(30);
v_date VARCHAR2(30);
BEGIN
SELECT user,TO_CHAR(sysdate,'DD/MON/YYYY HH24:MI:SS') INTO v_user, v_date FROM dual;
IF INSERTING THEN
INSERT INTO sh_audit (new_name, old_name, user_name, entry_date, operation)
VALUES (:NEW.sh_name, NULL, v_user, v_date, 'Insert');
ELSIF DELETING THEN
INSERT INTO sh_audit (new_name, old_name, user_name, entry_date, operation)
VALUES (NULL, :OLD.sh_name, v_user, v_date, 'Delete');
ELSIF UPDATING THEN
INSERT INTO sh_audit (new_name, old_name, user_name, entry_date, operation)
VALUES ( :NEW.sh_name, :OLD.sh_name, v_user, v_date, 'Update');
END IF;
END;
/
Then upon inserting the values:
INSERT INTO superheoes(sh_name) VALUES ('Supe');
======================================================================
I am getting the following Error message:
Error starting at line : 76 in command -
INSERT INTO superheoes(sh_name) VALUES ('Supe')
Error at Command Line : 76 Column : 13
Error report -
SQL Error: ORA-04098: trigger 'HR.SUPERHEROES_AUDIT' is invalid and failed re-
validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause:
A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed for the trigger.
*Action: Options are to resolve the compilation/authorization errors,
disable the trigger, or drop the trigger.
If I create the tables according to the trigger, the trigger works as you wrote it:
CREATE TABLE superheoes (sh_name VARCHAR2(20));
CREATE TABLE sh_audit
(
new_name VARCHAR2(20),
old_name VARCHAR2(20),
user_name VARCHAR2(20),
entry_date VARCHAR2(20),
operation VARCHAR2(20)
);
CREATE OR REPLACE TRIGGER superheroes_audit
BEFORE INSERT OR DELETE OR UPDATE
ON superheoes
FOR EACH ROW
ENABLE
DECLARE
v_user VARCHAR2(30);
v_date VARCHAR2(30);
BEGIN
SELECT USER, TO_CHAR(SYSDATE, 'DD/MON/YYYY HH24:MI:SS')
INTO v_user, v_date
FROM DUAL;
IF INSERTING
THEN
INSERT INTO sh_audit(
new_name,
old_name,
user_name,
entry_date,
operation
)
VALUES (
:NEW.sh_name,
NULL,
v_user,
v_date,
'Insert'
);
ELSIF DELETING
THEN
INSERT INTO sh_audit(
new_name,
old_name,
user_name,
entry_date,
operation
)
VALUES (
NULL,
:OLD.sh_name,
v_user,
v_date,
'Delete'
);
ELSIF UPDATING
THEN
INSERT INTO sh_audit(
new_name,
old_name,
user_name,
entry_date,
operation
)
VALUES (
:NEW.sh_name,
:OLD.sh_name,
v_user,
v_date,
'Update'
);
END IF;
END;
/
The trigger is compiled and works:
SQL> INSERT INTO superheoes(sh_name) VALUES ('Supe');
1 row created.
SQL> select * from sh_audit;
NEW_NAME OLD_NAME USER_NAME ENTRY_DATE OPERATION
-------------------- -------------------- -------------------- -------------------- --------------------
Supe ALEK 21/DIC/2016 15:25:37 Insert
I would check the table structure, schema, privileges, ...
Try this: Its working. Also check if you have execute privilege.
SQL> SELECT * FROM DBA_SYS_PRIVS where grantee = 'SYSUSR' and privilege = 'EXECUTE ANY PROCEDURE' ;
GRANTEE PRIVILEGE ADM
------------------------------ ---------------------------------------- ---
SYSUSR EXECUTE ANY PROCEDURE NO
Trigger:
CREATE OR REPLACE TRIGGER superheroes_audit
BEFORE INSERT OR DELETE OR UPDATE
ON superheoes
FOR EACH ROW
BEGIN
-- SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS')
-- INTO v_user, v_date
-- FROM DUAL;
IF INSERTING
THEN
INSERT INTO sh_audit (new_name,
old_name,
user_name,
entry_date,
operation)
VALUES (:NEW.sh_name,
NULL,
USER,
TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS'),
'Insert');
ELSIF DELETING
THEN
INSERT INTO sh_audit (new_name,
old_name,
user_name,
entry_date,
operation)
VALUES (NULL,
:OLD.sh_name,
User,
TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS'),
'Delete');
ELSIF UPDATING
THEN
INSERT INTO sh_audit (new_name,
old_name,
user_name,
entry_date,
operation)
VALUES (:NEW.sh_name,
:OLD.sh_name,
User,
TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS'),
'Update');
END IF;
END;
/
See Demo for Trigger functionality:
Tables:
CREATE TABLE superheoes (sh_name VARCHAR2 (20));
CREATE TABLE sh_audit (new_name varchar2(20),
old_name varchar2(20),
user_name varchar2(30),
entry_date varchar2(30),
operation varchar2(20));
Execution:
SQL> select * from superheoes;
no rows selected
SQL> select * from sh_audit;
no rows selected
SQL> insert into superheoes values('XING');
1 row created.
SQL> commit;
SQL> select * from sh_audit;
NEW_NAME OLD_NAME USER_NAME
-------------------- -------------------- ------------------------------
ENTRY_DATE OPERATION
------------------------------ --------------------
XING SYSUSR
21/DEC/2016 15:19:41 Insert
SQL> delete from superheoes;
1 row deleted.
SQL> commit;
Commit complete.
SQL> select * from sh_audit;
NEW_NAME OLD_NAME USER_NAME
-------------------- -------------------- ------------------------------
ENTRY_DATE OPERATION
------------------------------ --------------------
XING SYSUSR
21/DEC/2016 15:19:41 Insert
XING SYSUSR
21/DEC/2016 15:20:30 Delete

Resources