How to write two triggers on same table how it works?
Hello sir..
I have to write two triggers on same table for auditing different columns of different pages (may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ val,timestamp)
Now different users from different pages will update the data on same table may be same columns!
If we write directly, we will not be able to know which column is updated from different pages.
My question is how can we control the triggers to raise based on the pages
A trigger is executed whenever the table is inserted / updated / deleted (depend on trigger definition). It won't know what 'page' caused the operation. You can prepare a trigger for one page.
In order to fulfill your need, you need some way to tell the trigger where you are. There are many ways to accomplish this. Some possible methods are (please check the documents for detail)
DBMS_SESSION.SET_IDENTIFIER
DBMS_APPLICATION_INFO.SET_MODULEFor example, you can call DBMS_SESSION.SET_IDENTIFIER to set an ID from your page, and then call sys_context to read the ID back:
In Page:
exec dbms_session.set_identifier('Page1');
...In Trigger
pageid := sys_context('USERENV', 'CLIENT_IDENTIFIER') ;
...Note that if you use a connection pool, you may need to properly reset the session information before return, in order to avoid messing up the session information when the connection is used next time.
Similar Messages
-
Hi Friend.
I have to write two triggers on same table for auditing different columns of different users(may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_val,timestamp)
Now different users from different modules will update the data on same table may be same columns from different front end forms!
If we write directly, we will not be able to know which column is updated by which user.
My question is in this case how can we control the triggers to raise differently?You can use WHEN clause to fire a trigger only when some condition is true - you can check an user also,
look at simple example:
- suposse we have two users US1 and US2:
C:\>sqlplus sys as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Pn Gru 6 13:14:22 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> create user us1 identified by us1;
User created.
SQL> create user us2 identified by us2;
User created.
SQL> grant connect, resource to us1, us2;
Grant succeeded.
SQL> grant create public synonym to us1, us2;
Grant succeeded.and suposse we have a table with three columns + audit table:
SQL> connect us1
Enter password:
Connected.
SQL> create table tab123(
2 col1 number,
3 col2 number,
4 col3 number);
Table created.
SQL> create table audit_tab123(
2 username varchar2(100),
3 col1 number,
4 col2 number,
5 col3 number );
Table created.
SQL> grant select, update, insert on tab123 to us2;
Grant succeeded.
SQL> grant select, update, insert on audit_tab123 to us2;
Grant succeeded.
SQL> create public synonym tab123 for tab123;
Synonym created.
SQL> insert into tab123 values( 1, 1, 1 );
1 row created.
SQL> commit;
Commit complete.We want a trigger that is fired only by user US1 and only after update of COL1 and COL2
(COL3 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US1
2 AFTER UPDATE OF col1, col2 ON tab123
3 FOR EACH ROW
4 WHEN ( user = 'US1' )
5 BEGIN
6 INSERT INTO audit_tab123( username, col1, col2 )
7 VALUES( user, :new.col1, :new.col2 );
8 END;
SQL> /
Trigger created.And we want a second trigger that is fired only by user US2 and only after update of COL2 and COL3
(COL1 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US2
2 AFTER UPDATE OF col2, col3 ON tab123
3 FOR EACH ROW
4 WHEN ( user = 'US2' )
5 BEGIN
6 INSERT INTO audit_tab123( username, col2, col3 )
7 VALUES( user, :new.col2, :new.col3 );
8 END;
9 /
Trigger created.and now let test our triggers:
SQL> connect us1/us1
Connected.
SQL> update tab123 set col1 = 22;
1 row updated.
SQL> update tab123 set col2 = 22;
1 row updated.
SQL> update tab123 set col3 = 22;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from audit_tab123;
USERNAME COL1 COL2 COL3
US1 22 1
US1 22 22
SQL> connect us2/us2
Connected.
SQL> update tab123 set col1 = 333;
1 row updated.
SQL> update tab123 set col2 = 333;
1 row updated.
SQL> update tab123 set col3 = 333;
1 row updated.
SQL> commit
2 ;
Commit complete.
SQL> select * from us1.audit_tab123;
USERNAME COL1 COL2 COL3
US1 22 1
US1 22 22
US2 333 22
US2 333 333As you see, each trigger is fired only once, first triger only for user US1 and columns COL1 and COL2,
and second trigger only for user US2 and only after update of COL2 and COL3.
I hope this will help. -
Create ViewCriteria comparing two columns from same table
Does anyone know how I can create a ViewCriteria where clause that compares two columns from the same table?
For example if I had two integer columns (MINSAL and MAXSAL) and wanted to see if they are equal. I would normally do the following SQL below.
SELECT * FROM EMPL
WHERE MINSAL = MAXSALIt works, but it is not ideal.
Setup a Transient column that performs a groovy evaluation of MINSAL=MAXSAL and then my ViewCriteria evaluates the column to true and I set Query Execution Mode to Both. -
Compare two rows in same table
Hi,
I want to compare two rows (some columns) in the same table, and if the data in the data columns is different, I want to pick the latest one. The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows. Is this possible in sql. I can do this in Pl/sql, but dont want to use it. Eg
address_id, postal_code, person_id,last_update_date
123, pn123,1,12-JAN-01
124,pu124,1,13-JAN-01
I want to be able to retrieve just the second line.
Any help is appreciatedWelcome to the forum!
Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
>
The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows.
>
Your question is a little confusing because you are using terms like 'date tracked' and 'effective date' without explaining exactly what your definitions of those terms is.
Why do you want the latest record ONLY if the postal code is different? What if the address is different? Then which record do you want?
Why not just take the record for each person/company that has the latest date? If the data is the same then it doesn't which record you get so the one with the latest date will do. And if the data is different taking the one with the latest date gives you the latest data.
The classic definition of effective date is 'the date the information becomes effective'. Information with a given effective date is NOT in effect before that date and is SUPERCEDED when data is entered with a later effective date if the actual date is later than or equal to the effective date. Using your data
>
123, pn123,1,12-JAN-01
124,pu124,1,13-JAN-01
>
The first record IS NOT effective for dates prior to 12-JAN-01. In fact for a query looking for data prior to that date there isn't any data.
The first record is also NOT effective for dates on or after 13-JAN-01. Only the second record is effective.
If you added a record for 14-JAN-01 this record would not be effective until on or after that date (i.e. not for another 4 1/2 months).
So for the classic definition of effective date the query needs to provide the AS OF date to use to obtain the data. If, as in your system, you are not allowed to create records with dates in the future and you just want the latest record then you can just select the record with the MAX(myDate) value for the given person_id, address_id or whatever your key values are.
Edited by: rp0428 on Aug 11, 2012 7:50 AM -
How to Concatenate two rows of same table
Hi Friends
I have table
No Name Id
1 Raju 6
2 Dhanshree 7
3 Shital 6
4 Priya 7
I want the query that should display
Raju Dhanshree.
Shital Priya
That Means whenever 6,7 number come the query should Concatenate The name colume1 150 IEEE TRANSA CTIONS ON MICR O W A V E THEOR Y AND TECHNIQ UES, V OL. 50, NO. 1, J ANU AR Y 2002
Times-Roman 4
2 A Miniaturized MMIC Analog Phase Shifter Using
Times-Roman 16
3 T w o Quarter-W a v e-Length T ransmission Lines
Times-Roman 16
4 Hitoshi Hayashi
Times-Roman 7
5 , Member , IEEE
Times-Italic 7
6 , T adao Nakaga w a
Times-Roman 7
7 , Member , IEEE
Times-Italic 7
8 , and Katsuhik o Araki
Times-Roman 7
9 Abstract—
Times-BoldItalic 6
10 This paper describes a miniaturized monolithic-mi-
Times-Bold 6
11 cr o w a v e integrated-cir cuit (MMIC) analog phase shifter using tw o
Times-Bold 6
12 quarter-wa v e-length transmission lines. A con v entional analog
Times-Bold 6
13 phase shifter employs an analog phase-shifter topology using a
Times-Bold 6
14 3-dB 90
Times-Bold 6
15 branch-line h ybrid r equiring f our quarter-wa v e-length
Times-Bold 6
16 transmission lines. Thus, in the f irst stage of our study , w e
Times-Bold 6
17 pr esent a new analog phase-shifter topology using only tw o
Times-Bold 6
18 quarter-wa v e-length transmission lines. The phase shifter her e
Times-Bold 6
19 has only one-half as many transmission lines as a con v entional
Times-Bold 6
20 analog phase shifter using a 3-dB 90
Times-Bold 6
21 branch-line h ybrid, and the
Times-Bold 6
22 cir cuit can be miniaturized to less than one-f ourth as compar ed to
Times-Bold 6
23 the con v entional analog phase shifter . Furthermor e, we sho w that
Times-Bold 6
24 the operating fr equency range of the phase shifter is v ery wide and
Times-Bold 6
25 can obtain lar ge phase v ariation with small capacitance v ariation.
Times-Bold 6
26 Next, an experimental
Times-Bold 6
27 -band MMIC analog phase shifter is
Times-Bold 6
28 pr esented. A phase shift of mor e than 180
Times-Bold 6
29 and an insertion loss
Times-Bold 6
30 of 3.6
Times-Bold 6
31 1.1 dB ar e obtained at the fr equency range fr om 12 to
Times-Bold 6
32 14 GHz. The chip size of the experimental MMIC phase shifter is
Times-Bold 6
33 less than 3.0 mm
Times-Bold 6
34
How will use on this data -
Two queries on same table in sender JDBC adapter
Hi all..
My requirement is as follows....
query a table and fetch rows where column Error="true"
If there are no records in the table satisfying the above condition ,i want to send a mail stating that there are not records with error flag set to "true"
But the problem is i wont get a message to PI if there are no records.
If i write a query to get the count of records where column Error="true",Obviously the count would be zero. Using this message from database i can send a mail.
Now please let me know if i can write both the queries in query SQL statement? if so howshould be the source structure?
Thanks
Ram..Hello ram,
As far as i know it is not possible to use two different SQL statements in the sender adapter, though you can try with the join statement.
For further information refer this discussion
[Multiple Select Possible?|How to call multiple SQL using the JDBC adapter;
Regards,
Prasanna -
Link two identical databases, same tables, same fields
Post Author: CathyH
CA Forum: Data Connectivity and SQL
I have two Accpac databases (two different companies, one Canadian one US). I have created the same report for both companies using their respective data tables and another where I have converted the US funds to Canadian.
I would now like to create one report that links the two companies.
I will be sorting on Customer. Whenever a customer is set up in the US company a duplicate is set up in the Canadian company but Canadian customers are not duplicated in the US company (it's just something we have to do for billing purposes) so there will always be many more Canadian customers.
I would like the report to add together any matching customers in the US and Canadian companies but also report the customers that are strictly Canadian.
Can anyone help me? Please!
CathyPost Author: synapsevampire
CA Forum: Data Connectivity and SQL
You might do this using advanced SQL on the database in a View or SP.
Or another, somewhat fugly solution is to create a main report with the canadian database, group by the company, insert a subreport using the US database at the group level (header or footer), and link by the company.
You can now respond to no rows in the subreport to indicate those that are not in the US database.
Ain't purdy, but it'll work.
-k -
Select column 1 into two column from same table
Dear Sir
I have a data like
studid makr tottal credit total average mark semester
251; 249.84; 41; 6.09; 1
106; 285.32; 42; 6.79; 1
285; 263.88; 38; 6.94; 1
251; 202.40; 28; 7.23; 2
106; 293.20; 39; 7.52; 2
285; 228.14; 39; 5.85; 2
I want to select average mark semester1 and semester 2 in different column
studid average_mark_ semester1 average_ mark_ semester_ 2
251 6.09 7.23
106 6.79 7.52
285 6.94 5.85
please help me
regards
sanat kumar
thanks in advanceDear Sir,
Thank u for your prompt answer.
But I want to select student id and average mark based on semester
out put supposed to be
student id average_makr_sem1 average_mark_sem2
251 6.09 7.23
106 6.79 7.52
285 6.94 5.85
I want to select the average mark in different column based on semester
Please look into
thanks
regards
sanat -
Combine 2 Queries (from SAME table) into a SINGLE query
I have this two queries (from SAME table), and want to combine into one SINGLE query, how?
How can we use CASE WHEN THEN for such situation?
Query1:
SELECT t_inner.*,
Floor(t_inner.ProductiveTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.ProductiveTime,3600) / 60),2,0) || 'min:' AS Productive_Time,
Floor(t_inner.OperatorDownTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.OperatorDownTime,3600) / 60),2,0) || 'min:' AS OperatorDown_Time
FROM
(SELECT SYSTEMTYPE,
sum(TIME_TEST + TIME_STEP) AS ProductiveTime,
sum(TIME_IDLE) AS OperatorDownTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO != '9999999999'
GROUP BY SYSTEMTYPE ) t_inner
Query 2:
SELECT t_inner.*,
Floor(t_inner.MachineDownTime/ 3600) || 'hr ' || LPAD(Floor(Mod(t_inner.MachineDownTime,3600) / 60),2,0) || 'min' AS MachineDown_Time
FROM
(SELECT SYSTEMTYPE,
sum(TIME_IDLE) AS MachineDownTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO = '9999999999'
GROUP BY SYSTEMTYPE) t_inner
see http://postimg.org/image/koq87iyyz/ and
http://postimg.org/image/fv3zxa38nwith the first query,
SELECT t_inner.*,
Floor(t_inner.ProductiveTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.ProductiveTime,3600) / 60),2,0) || 'min' AS Productive_Time
FROM
(SELECT SYSTEMTYPE,
--sum(TIME_TEST) AS TIME_TEST,
--sum(TIME_SYSTEM) AS TIME_SYSTEM,
--sum(TIME_STEP) AS TIME_STEP,
--sum(TIME_IDLE) AS TIME_IDLE,
sum(TIME_TEST + TIME_STEP) AS ProductiveTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO != '9999999999'
GROUP BY SYSTEMTYPE) t_inner
it gives output as from
http://postimg.org/image/koq87iyyz/
with the second query,
SELECT t_inner.*,
Floor(t_inner.MachineDownTime/ 3600) || 'hr ' || LPAD(Floor(Mod(t_inner.MachineDownTime,3600) / 60),2,0) || 'min' AS MachineDown_Time
FROM
(SELECT SYSTEMTYPE,
sum(TIME_IDLE) AS MachineDownTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO = '9999999999'
GROUP BY SYSTEMTYPE) t_inner
it gives output as from
http://postimg.org/image/fv3zxa38n/
I want to come those 2 queries into a single query, such that it gives both outputs as above. Let me know if you need any other information. thanks. -
How to write two item in the same line?
In the smartforms,how to write two item in the same line?
eg
1 ************* 2 *****************
3 ************** 4 ******************
5 ***************
Anyone got any idea to do this.
Thanks in advanceHi,
In the smartform the main windows is 20cm.I use the table output my data.Because the output is two item in same line,I define two rows in the table line type.
Question:
Should I define the table width 20cm?
In the main area of table , should I define two folders and each of folder include a line? The second item I had already defined as Append Directly,but the item 1 and item 2 don't in the same line.
Regards -
How can i update two block that they data source is same table .
i design user interface .
there are tow block ,they datasource is same table but differe field .
when i input a record ,i must input tow block ,then commit . for this .the total record is save in database .
how can i write those code .Trying to hide your identity?
Why do you have two separate blocks here if there are different fields in each. The feilds in a block can be spread over multiple canvases / windows so layout is not a reason.
If you are in a situation where two blocks are displaying the same record for update them you'll have the potential of data consistancy problems as well.
So explain what you're trying to do with the two separate blocks and maybe we can come up with a better way to implement it. -
Two triggers in the same table and event
If I created two triggers on the same table and event (before insert), which of them will be triggered first ?...
The problem from the beginning is that I created the second one as after insert and in the body of the trigger I wrote (:new.xxx:= value) ... then an error (that it should be before insert trigger or update trigger), so I created it as before update ,,, but I have already before update trigger (for primary key)..... and the problem -I think- which of them start first...
Can make the second one as after insert and make update statement instead of assigning (:new.xxx:= value).....
RegardsIf I created two triggers on the same table and event
(before insert), which of them will be triggered
first ?...As already mentioned, prior to 11g the order of firing is undetermined.
The problem from the beginning is that I created the
second one as after insert and in the body of the
trigger I wrote (:new.xxx:= value) ... then an error
(that it should be before insert trigger or update
trigger), so I created it as before update ,,, but I
have already before update trigger (for primary
key)..... and the problem -I think- which of them
start first...If there is a conflict of interest inside the code then you will have to alter your design principle around this to cater for it. Also consider combining the code into a single before insert trigger to prevent any confusion.
Can make the second one as after insert and make
update statement instead of assigning (:new.xxx:=
value).....Attempting to update or query the same table as is causing the trigger to fire will result in a mutating table error. You can't do this. -
Hi,
I want to center two different text row that are in the same table but one on the center and the other one on the left. I put a <span> tag hoping that it has been overwhelmed the table's class properties The .bottomsel's font-family and the .Cig84's font-family and colour work but the text-align don't: they're both on the left.
These are my source and CSS codes:
Source:
<table width="600" border="0">
<tr>
<td class="bottomref"><p><span class="bottomsel">| <a href="index.html" target="_self">Main</a> | <a href="about.html" target="_self">About</a> | <a href="clients.html" target="_self">Clients</a> | <a href="contact.html" target="_self">Contact</a> |</span><br />
<span class="credits">Credits: <span class="Cig84">Cig84</span></span></p></td>
</tr>
</table>
CSS:
.bottomsel {
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
.credits {
text-align: left;
.Cig84 {
color: #F00;
font-family: "Comic Sans MS", cursive;Use paragraph tags with CSS classes.
CSS:
.center {text-align:center}
.left {text-align:left}
HTML:
<table width="600" border="0">
<tr>
<td class="bottomref">
<p class="center">This text is center aligned</p>
<p class="left">This text is left aligned</p>
</td>
</tr>
</table>
Nancy O. -
How to compare two fields from the same table in the select statement
Hi, friends
I try to compare tow fields from the same table, but no result,
For example, this
data: cptotchek tyep i.
select count(*) into cptotchek
from aufk where erdat = aufk-idat2 .
The result is cptotchek = 0, but there are the records in aufk , where, aufk-erdat = aufk-idat2.
Please, help me, i don't use the loop statement for optimize my program.
RegardsHi ,
it will not return any value when you are using column of same table
such as Date Field , Because while Using Aggregate Function it will not check with self column
. For that you have to take data in one internal table and then you can work on it .
And if you are worried about Performance it will not affect , untill you are selecting only required data .
you can try this way .
data: cptotchek type i.
types : begin of w_aufk.
include structure aufk .
types : end of w_aufk .
data : it_aufk type standard table of w_aufk with header line .
select * into corresponding fields of table it_aufk
from aufk .
loop at it_aufk .
if it_aufk-erdat = it_aufk-idat2 .
write : / it_aufk-erdat , it_aufk-idat2 .
else .
delete it_aufk .
endif .
endloop.
Regards
Deepak. -
How to give two values of same field in read Statment
Hi,
Please Tell me how to give the two values of same field in read statements Condition.
i.e
Read table it_tab with key matnr = '1' or matnr = '2'.
With Regards
KesavaperumalHi Kesavaperumal,
<li>You can not use OR operator with READ TABLE statement.
<li>You have to use different fields of the internal table in where condition.
<li>If you want to compare with two values, you need to use LOOP statement.
LOOP AT it_mara WHERE matnr = '1' or matnr = '2'.
"Write code
ENDLOOP.
Thanks
Venkat.O
Maybe you are looking for
-
What can be done to have keynote & numbers to open in iWork '09
Loading up a disk for iWork '09 gives the three apps Pages, Numbers, and Keynote. However, only Pages opens properly. Numbers partially opens, but I can't get access to files I've made in the past. Keynote doesn't open at all. The version of iWor
-
Jodc tasks exits with error message
Hello, when trying to compile my application, the jdoc (enhancer) task of my build.ant gives the following error message: Could not create task of type : jdoc due to java.lang.VerifyError: (class: com/solarmetric/modules/integration /ant/TaskBase, me
-
Business Importance of CCMS alerts and Early Watch Alerts configuration
Hi All, I have to present to the management how will configuring CCMS alerts and EWA alerts impact the business and how will it help in maintaining our business and existing scenario through the same. Could some body provide me with the PPT presentat
-
Is it possible to define my own user control and use it in the B1 Add-On development. If so, can it load into the screen painter??
-
Hi expert, Pl. tell me the path for transporting number range for production order from development server->quality ->Production. Regards L.B.Yadav