Trigger - Identifying Modified Columns
Hi All,
I have created AFTER INSERT OR DELETE OR UPDATE FOR EACH ROW trigger. To audit the changes, if update or delete performed old values will get insert into PRM_CURFILEDATE_AUDIT and if insert happen new values will get insert.
In PRM_CURFILEDATE_AUDIT table there is column called COMMENTS. If value for particular column gets updated I want to add that column name along with new value.
Trigger:-
CREATE OR REPLACE TRIGGER CRUFILEDATE_AUDIT_TRG
AFTER INSERT OR DELETE OR UPDATE ON CURFILEDATE_TEST
FOR EACH ROW
BEGIN
DECLARE
lv_Updtype CHAR(10);
lv_Sid VARCHAR2 (30);
lv_Machine VARCHAR2 (64);
lv_Osuser VARCHAR2 (30);
lv_Program VARCHAR2 (48);
BEGIN
Select sid
Into lv_Sid
From v$session
where Audsid = (Select Sys_context('Userenv','SessionID') From Dual);
Select Machine,Program,Osuser
Into lv_Machine,lv_Program,lv_Osuser
From V$session
Where Sid = lv_Sid ;
IF Inserting
Then lv_Updtype := 'INSERT';
Elsif Deleting
Then lv_Updtype := 'DELETE';
Elsif Updating
Then lv_Updtype := 'UPDATE';
End If;
-- Insert record into PRM_CURFILEDATE_AUDIT table
IF Inserting THEN
Insert into PRM_CURFILEDATE_AUDIT ( FILETYPE,CHNGDATE,FILEDATE,RECDESC,APPL,UPDTYPE,OSUSER,MACHINE,PROGRAM,RUN_DATE)
Values
(:new.FILETYPE ,:new.CHNGDATE,:new.FILEDATE ,:new.RECDESC,:new.APPL,lv_UPDTYPE,lv_OSUSER ,lv_MACHINE,lv_PROGRAM ,to_char(SYSDATE,'YYYYMMDD - hh24:mi:ss'));
END IF;
IF Updating OR Deleting Then
Insert into PRM_CURFILEDATE_AUDIT ( FILETYPE,CHNGDATE,FILEDATE,RECDESC,APPL,UPDTYPE,OSUSER,MACHINE,PROGRAM,RUN_DATE)
Values
(:old.FILETYPE ,:old.CHNGDATE,:old.FILEDATE ,:old.RECDESC,:old.APPL,lv_UPDTYPE,lv_OSUSER ,lv_MACHINE,lv_PROGRAM ,to_char(SYSDATE,'YYYYMMDD - hh24:mi:ss'));
End if;
END;
END;
Thankx in advance.
so.. what is your question?
you could change this
Select sid
Into lv_Sid
From v$session
where Audsid = (Select Sys_context('Userenv','SessionID') From Dual);
Select Machine,Program,Osuser
Into lv_Machine,lv_Program,lv_Osuser
From V$session
Where Sid = lv_Sid ;to this
Select sid , Machine,Program,Osuser
Into lv_Sid , lv_Machine,lv_Program,lv_Osuser
From v$session
where Audsid = Sys_context('Userenv','SessionID');no need for two different queries...
or maybe, only use the SYS_CONTEXT:
lv_Sid := sys_context ('userenv', 'sessionid');
lv_Machine := sys_context ('userenv', ''); --<--- look up yourself
lv_Program := sys_context ('userenv', '') --<--- look up yourself;
lv_Osuser := sys_context ('userenv', 'os_user');http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions165.htm#SQLRF06117
and why do you change the DATE to a CHAR when you insert your record?
any reason why you would use CHAR instead of VARCHAR2? ( CHAR(10) for this lv_Updtype )
Similar Messages
-
Identifying updated column in materialized view logs
Hi all,
I created a materialized view log for a table with three columns(say colA,colB,colC). Is there any way to identify which column got updated among these three columns? through the entries in mat view logs?
any inputs on this ll be of great help.
Thanks in advance.
gopiCan someone tell me about M_ROWS$$ column in Materialized view.
I am in confucion. -
Finder Window - Date Modified Column Keeps Changing
When I open a Finder window, change the size of the "Date Modified" column then close the Finder window, the next time I open the same Finder window, the "Date Modified" column will compress the size of the column.
Why isn't Finder 10.9 maintaining my column changes?
Any assitance or insight whould be appreciated.I solved the scrunched Date Modified column header in a similar fashion but added the Date Added field, which fixed the width of both Date columns.
After doing so, I now find both Date-oriented columns display and read dynamically the actual date and time.
I'm now looking for a solution to that issue, explained here:
finder window date added date modified show date time always -
Items "date modified" column when viewing files as list in finder
I'm not really sure if I can change this viewing option, but i will give it a try:
when viewing files as list in finder, "yesterday" items "date modified" column shows up with the term "yesterday", while this does not happen for "today" items, where what shows up is just today's date and not the term "today".
I found this rather confusing, since it is not immediate: i.e. if I want to check for items modified today at a glance, i need to pick today's date from a ist with a number of different dates. As a matter of fact, it's a way easier when checking for yesterday's items.
Suggestions anyone?
Thanks!toygal wrote:
I am new to Aperature and not very computer savvy so please provide "dummy's guide to" responses.
toygal -- welcome to the Aperture user-to-user forum. iPhoto was designed with you in mind. Aperture is 100x more complicated (and no faster). I strongly recommend that you revert to iPhoto and use it. Compared to Aperture, it will bring you more pleasure and cause you much less frustration. Whoever told you that Aperture is faster not only was wrong, they failed to take into consideration the hours that you would have to practice to become comfortable with it.
Here are some threads which briefly touch on the difference between iPhoto and Aperture -- use the search to find many more.
http://discussions.apple.com/thread.jspa?messageID=13183439�
http://discussions.apple.com/thread.jspa?messageID=12906017�
http://discussions.apple.com/thread.jspa?messageID=12901779�
Message was edited by: Kirby Krieger -
Manage Table / Modify column does not display current values
Hi,
when I choose "Modify column" from the menu "Manage table", the current properties of the column, i.e. type, size and so on, are not shown, but are defaulted to whatever value has been defined inside that page, so the column type is always set to "Number" for instance.
It would be definitely better to retain the current values, in my humble opinion.
Bye,
FlavioI have also run into this problem. I am running IQ 16.0 sp1. I wanted to increase the number of characters in one of the columns so I have to create a new column, copy the data, delete the old column then rename the new column.
Is there any reason the MODIFY function is not implemented in IQ? -
Update trigger: identify which field changed
Is there any way to identify which field was changed when an update trigger fires? I need to be able to update another field if any field excluding 1 was changed.
Something like
for each field in :new
if field.name != "dateref" then
if field.modified then
altered=true
exit for
endif
endif
next
if altered then :new.updatetype="A"This will do it
CREATE OR REPLACE my_trigger BEFORE UPDATE
OF col2, col3, col4 ON my_table FOR EACH ROW
BEGIN
:new.updatetype='A';
END;
/If your table has a lot of columns this will be a bit of a drag to type all those column names. Unfortunately, as far as I know, there is no OF ALL COLUMNS EXECPT col1 ON
syntax.
Cheers, APC -
Would it be faster to use a trigger or modify the insert query?
We have a table that currently has latitude, longitude columns and are trying to decide what route to go as far as adding spatial data to future records. A spatial index will be placed on the new column.
There appear to be 3 solutions:
1 Create a materialized view which creates the spatial column based on the current latitude and longitude columns.
2 Create a trigger on the table that will populate the new spatial column on insert/update.
3 Modify the code to insert a spatial value into the new spatial column.
Due to the nature of the data we are not willing to use method 1.
What we are trying to figure out is which method, 2 or 3, will insert faster.
Has anyone done tests to determine if an insert with a spatial object is slower than an insert on a table with a trigger that creates a spatial object?
Thanks,
PatPat,
Note that you don't need to store latitude, longitude in sdo_geometry type in order to spatially index it. Instead you can create a function that returns an sdo_geometry based on two numeric columns, then create a function based index on that. Its described here:
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11830/sdo_exten.htm#i1005799
Also note that in the sdo_geometry type, you need to define the data as longitude/latitude and not the other way around.
If you do want to create a column with sdo_geometry column, I'd recommend your third option. As a general principle I avoid triggers unless absolutely necessary. Triggers invariably lead to confusion when you (or someone else) revisits this code in the future. Also the change of context between and SQL and PL/SQL has a performance hit. Here's a simple test:
SQL> CREATE TABLE long_lat_no_trigger (
2 geometry SDO_GEOMETRY);
Table created.
SQL>
SQL> CREATE TABLE long_lat_with_trigger (
2 longitude NUMBER,
3 latitude NUMBER,
4 geometry SDO_GEOMETRY);
Table created.
SQL>
SQL> CREATE OR REPLACE TRIGGER long_lat_to_geometry
2 BEFORE INSERT ON long_lat_with_trigger FOR EACH ROW
3 DECLARE
4 BEGIN
5 :new.geometry := SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(
6 :new.longitude, :new.latitude, NULL), NULL, NULL);
7 END;
8 /
Trigger created.
SQL>
SQL> SET TIMING ON
SQL> INSERT INTO long_lat_no_trigger (geometry) (
2 SELECT
3 SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(
4 dbms_random.value(0,180), dbms_random.value(0,90),
5 NULL), NULL, NULL)
6 FROM DUAL
7 CONNECT BY LEVEL <= 1000000);
1000000 rows created.
Elapsed: 00:00:31.96
SQL>
SQL> INSERT INTO long_lat_with_trigger (longitude, latitude) (
2 SELECT
3 dbms_random.value(0,180),
4 dbms_random.value(0,90)
5 FROM DUAL
6 CONNECT BY LEVEL <= 1000000);
1000000 rows created.
Elapsed: 00:01:21.15Cheers,
John -
How to Identify unused columns in a table
Hiiya..
Is there a way to find out that following columns of table X,Y, Z have never been used. So that, I can check with the FCs and mark them un-used (using ALTER TABLE).
I don't want to go through every line of (avlbl) PLSQL code to identify that so and so column of so and so table has never been used. Is there any view or any sys proc/pkg using which I can identify them.
TIAGuido
Not getting you exactly. What I am doing is pick all the columns one by one and search in all_source (like where TEXT like %COLUMN_NAME%). Now what about 'AND <UnusedColumn> IS NULL'
Sidhu -
Efficiently identify modified values in JTable
Hi
I have a table with about 20 columns and 800 rows,
It was read only , now i have open this table for editing.
The user will update cells,and then click update database which will update those cells in database,
is there a efficient way to do this, or do i have to keep old values, and then read all table to compare it with old values to find out which are modified
Is there a row or cell listener which i can use to keep track of cells or rows which where modified,
This should be smart enough to differentiate between just a click and double click for the user to modify this value.
Any ideas or code would help
AshishOne technique is to override the setValueAt( ) method of your TableModel and update the database instantly when the value changes. (Unless this is not the requirement)
Updates to a database record can take just a few seconds so this shouldn't hamper performance. However, you can just as well spawn a new thread and run the update from there.
ICE -
Trigger to blob column in Oracle - Need Help
Hi,
I need any help on Oracle Trigger
I have two table
- BIODATA_TABLE
- ADM_GALERY_PICTURE
All two table contain column SPIC_PICTURE2 that is blob column.
If the picture column update in table BIODATA_TABLE, i want it to update also in ADM_GALERY_PICTURE,
I have created the trigger to BIODATA_TABLE.
When i try to update the picture, the picture on the ADM_GALERY_PICTURE does not updated.
Below is my trigger, Please help me to correct it
CREATE OR REPLACE TRIGGER TRANSFER_PICTURE_TRIGGER
AFTER INSERT OR UPDATE
ON BIODATA_TABLE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
tmpVar := 0;
IF UPDATING
THEN
UPDATE ADM_GALERY_PICTURE
SET SPIC_PICTURE2 = :NEW.SPIC_PICTURE2
WHERE ADM_GALERY_PICTURE.SPIC_BIODATA_ID = :NEW.SPIC_BIODATA_ID;
END IF;
EXCEPTION
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END TRANSFER_PICTURE_TRIGGER;
thanksuser450549 wrote:
Hi,
I need any help on Oracle Trigger
I have two table
- BIODATA_TABLE
- ADM_GALERY_PICTURE
All two table contain column SPIC_PICTURE2 that is blob column.
If the picture column update in table BIODATA_TABLE, i want it to update also in ADM_GALERY_PICTURE,
I have created the trigger to BIODATA_TABLE.
When i try to update the picture, the picture on the ADM_GALERY_PICTURE does not updated.
Below is my trigger, Please help me to correct it
CREATE OR REPLACE TRIGGER TRANSFER_PICTURE_TRIGGER
AFTER INSERT OR UPDATE
ON BIODATA_TABLE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
tmpVar := 0;
IF UPDATING
THEN
UPDATE ADM_GALERY_PICTURE
SET SPIC_PICTURE2 = :NEW.SPIC_PICTURE2
WHERE ADM_GALERY_PICTURE.SPIC_BIODATA_ID = :NEW.SPIC_BIODATA_ID;
END IF;
EXCEPTION
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END TRANSFER_PICTURE_TRIGGER;
thankswithout your tables & without your data we can't run or test your code.
the picture on the ADM_GALERY_PICTURE does not updated.OK, I believe you, but what EXACTLY does occur? -
General Query to identify parent columns and child columns in a table
Does anyone know a general query that can be run to identify the child records associated with the parent column within a single table.....and between other tables?
Am I correct in assuming the parent column is the 'primary key'?
Thanks.....I'm a new to oracle...and need some help understanding
my company's crazy DB structureYou can use
User_Constraints
User_Cons_Columns
views to identify parent and child table columns
SELECT * FROM User_Constraints WHERE Constraint_Type = 'R' AND Table_Name = '<TABLENAME>';
SELECT * FROM User_Cons_columns WHERE Constraint_Name = '<Name from Above query>';
will give you columns of the parent table (if you use value from constraint_name) and of child table (if you use value from r_constraint_name).
HTH.. -
Hi,
I need to alter the data type of a date column to varchar2(6).
Here's the tabel I need to change.
SQL> desc foo
Name Null? Type
PK NUMBER
DOB DATE
I understand that I must NULL out the DOB column before I can do the ...
alter table foo modify (DOB varchar2(6));
... so I create another table like so ...
SQL> create table foo2 as select * from foo;
Table created.
... now I can do ...
SQL> update foo set DOB = NULL;
100 rows updated.
SQL> commit;
Commit complete.
... now I do ...
SQL> alter table foo modify ( dob varchar2(6));
alter table foo modify ( dob varchar2(6))
ERROR at line 1:
ORA-01401: inserted value too large for column
Why do I get this error?
thanksDepending too regarding the nls_date_format in your system, the result when you query the date will be higher o viceversa.
As you realized try with varchar2(8), if it fails try
to increase that number.
Joel P�rez -
Ora-01440 on modifying column - urgent needed
Hi
we have following table
SQL> desc VULNERABILITY_REG_PERIODS
Name Null? Type
CLIENT_ID NOT NULL NUMBER(10)
ASSOCIATED_FAMILY NUMBER(7)
HCP VARCHAR2(8)
STAFF_TYPE VARCHAR2(2)
DATE_ON_PROTECTION NOT NULL DATE
DATE_OFF_PROTECTION NOT NULL DATE
SECTOR VARCHAR2(2)
AUDIT_TIMESTAMP DATE
AUDIT_ID NUMBER
AUDIT_ORIGIN VARCHAR2(30)
RECORD_STATUS CHAR(1)
i am trying to modify the column
alter table VULNERABILITY_REG_PERIODS modify audit_id number(10,0);
the max length of audit_id is 4
SQL> select max(audit_id) from VULNERABILITY_REG_PERIODS;
MAX(AUDIT_ID)
9936
what is the reason for above error when modifyng this column
thanx
kedarHi,
I think that internally, Oracle understand that NUMBER is a synonym for NUMBER(38).
The precision can range from 1 to 38. Then, that's why this error is happening;
You can try this below:
SGMS@ORACLE10> create table x (cod number);
Table created.
SGMS@ORACLE10> insert into x values (1000);
1 row created.
SGMS@ORACLE10> commit;
Commit complete.
SGMS@ORACLE10> desc x
Name Null? Type
COD NUMBER
SGMS@ORACLE10> alter table x add (temp number);
Table altered.
SGMS@ORACLE10> update x set temp = cod;
1 row updated.
SGMS@ORACLE10> update x set cod = null;
1 row updated.
SGMS@ORACLE10> alter table x modify cod number (10,0);
Table altered.
SGMS@ORACLE10> update x set cod = temp;
1 row updated.
SGMS@ORACLE10> alter table x drop column temp;
Table altered.
SGMS@ORACLE10> desc x
Name Null? Type
COD NUMBER(10)
SGMS@ORACLE10>Cheers -
Modify column in an internal table
Hi Friends,
I have an internal table itab1 which has a column called zpo_number .
I am getting the PO from a BAPI call storing in a field w_ponumber.
I have the code below . THe table itab1 has rows all having the same matnr .
How can I modify all the rows of the table with the same w_ponumber ?
Thanks!
Loop at itab1
babpi call get po number
w_ponumber.
MODIFY itab1
endloop.simplicity change to your original code provided:
Loop at itab1
babpi call get po number
w_ponumber.
itab1-z_ponumber = w_ponumber.
MODIFY itab1
endloop.
Or -
Loop at itab1
babpi call get po number
itab1-z_ponumber.
MODIFY itab1
endloop. -
How to identify what columns are being suppressed
Hi,
I have a database that may be masking some columns via a VPD. I'd like to identify the policies and the columns that are masking it. I have checked ALL_POLICIES (and DBA_POLICIES) but (I think) it doesnt show the columns that are being masked. What system tables should I be looking at for this detail. I couldn't locate this information in the Oracle documentation. Thanks.
Harold.Hi,
Query DBA_SEC_RELEVANT_COLS
Salman
Maybe you are looking for
-
File does not exist: /oa_servlets/AppsLogin
Hi. The Apache error log reads thus: File does not exist: /oa_servlets/AppsLogin. The login page appears. BUt when selecting the EBS suite link, or OAM link, the HTTP 404 Not Found appears. I have checked that all services are up on the server. I hav
-
Error while registering plugin for custom schedule task
Hello, I am trying to register a plugin for creating a custom scheduled task. I have referred to the document http://docs.oracle.com/cd/E23943_01/doc.1111/e14309/refsched.htm Followed the below steps- 1. Updated the task.xml as below taken from MDS d
-
My galaxy s 4 mini is stuck in safe mode, Help!!!
I have tried resetting my phone, taking the battery out and taking the sim card out and nothing is working....Please help!!!
-
Monitoring RAID with Solaris 10 x86 and Dell PowerEdge 2650 PERC 3/Di
Hello, I have a PowerEdge 2650 with the PERC 3/Di RAID controller. The OS installed is Solaris 10 8/07 U4. Currently RAID is configured through the BIOS and it works fine, but I have no way to monitor the status of the drives. Is there a command to s
-
EPM 11.1.2 installing sucessfully
Hi, I am trying to re-install the epm 11.1.2 on windows 2008 sp2 and the installation seems to be sucessfully but in the console I get this message: "could not utilize start class: com.installshield.wizard.wizard" I am a administrator user.... and I