How can I write the trigger for the global temporary Table

Hi Grus,
How can I write the trigger for the global temporary Table.

I created the TWG with trigger using the script below.


CREATE A GLOBAL_TEMP GLOBAL TEMPORARY TABLE
(
EMP_C_NAME VARCHAR2 (20 BYTE)
)
ON COMMIT PRESERVE ROWS;


CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
BEFORE DELETE, UPDATE OR INSERT
ON GLOBAL_TEMP
REFERRING AGAIN AS NINE OLD AND OLD
FOR EACH LINE
BEGIN
INSERT INTO VALUES EMPNAME (: OLD.) EMP_C_NAME);
END;
/


trigger was created successfully, but her would not insert EMPNAME Table...

Please guide if mistaken or not? If not wanting to give a correct syntax with example


Thanks in advance,
Arun M M
BEGIN
INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
END;
you are referencing old value in insert stmt.

BEGIN
INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
END;

then run your app, it works very well...

CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
(
EMP_C_NAME VARCHAR2(20 BYTE)
)
ON COMMIT PRESERVE ROWS;

CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
BEFORE DELETE OR UPDATE OR INSERT
ON GLOBAL_TEMP
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
dbms_output.put_line(:OLD.EMP_C_NAME);
END;
/

create table EMPNAME as select * from GLOBAL_TEMP where 1=2

insert into GLOBAL_TEMP values('fgfdgd');
commit;
select * from GLOBAL_TEMP;
select * from EMPNAME;

output:
1 rows inserted
commit succeeded.
EMP_C_NAME
--------------------
fgfdgd               

1 rows selected

EMP_C_NAME
--------------------
fgfdgd               

1 rows selected

He got Arun

Published by: OraclePLSQL on December 28, 2010 18:07

Tags: Database

Similar Questions

  • How can I write the value of floats Unitronics vision230 PLC with modbus Ethernet

    How can I write the value of type Float in unitronics PLC Vision230 modbus ethernet (Ethernet Master Query.vi MB) usinsg I read and write register 32 bits, for example, I want to write the value 23.45 2nd Add. MF. And registry MF is the 32-bit registry. I read and write register 32-bit.

    Narendra.

    Narendra,

    Two characters can type cast into a uint16 you VI supports.

    To summarize. Take one (4 bytes). Flatten it to a string (4-byte) divided this string into two parts of 2 bytes each. Cast in u16 (16 x 2 = 32-bit).

    However, if you really want to follow the IEEE standards then you will need refer this KB. His is not that simple, but seems closer to what you are looking for.

    Amit

  • In Photoshop, how can I change the background (Mount table) from black to white. I must have hit something because it changed suddenly mid-project and I cannot find anywhere in preferences to solve this problem.

    In Photoshop, how can I change the background (Mount table) from black to white. I must have hit something because it changed suddenly mid-project and I cannot find anywhere in preferences to solve this problem.

    Right-click on the pasteboard, and you should have a choice of colours from timeline menu.

    I would add that you should have a file to open it or it won't work.

    Gene

  • Two part question: 1 How can I write a script for long Division, 2. How can I make my form?

    1. I have a field where I need to write a formula for a division problem: (power/population) / 365.  When I use the simplified field notation I get an error: the entered value does not match the format field.  I want the answer as a number with no decimal point.  If I format the field to 'no format' I don't get an error message but the answer comes with up to 10 digits after the decimal point.  I'd rather have the answer in integer without figures after the decimal point.  How can I write this in the custom calculation script?

    2. on accessibility - I never checked on the display/a Mode and unlocked the Acrobat/PDF compatibility.  Some users do not have a problem by filling out the form, but others are not allowed to fill that PDF/A is enabled for their document.  Is this something on their end?  Or is it something on my end blocking them?

    If you multiply by 100, it appears correctly. But if you need to retain the value of the field, you need to use a script to Format custom instead. If you need help, post again.

  • trigger on the global temporary table

    Hello

    I have a global temporary table

    CREATE GLOBAL TEMPORARY table to register)

    no_registre NUMBER primary key,

    date of create_time

    ) ON COMMIT DELETE ROWS.

    I have to write a trigger on the table every time that the insertion is made.

    create or replace trigger tri_register

    before inserting the REGISTER

    for each line

    Start

    : new create_Date: = sysdate;

    end;

    /

    This trigger can work on this registry table?

    Thank you

    913578 wrote:

    Sorry Karthik.

    the thing is that I did not have privelleges to test, I send the code to some dba who makes deployment.

    Sorry to hear that!

    Please tell me... We can write triggers on GTT?

    of course, you can!

    SQL > create a global temporary table registry
    () 2
    no_registre 3 number primary key,
    create_time date 4
    5)
    6 on the validation to delete lines;

    Table created.

    SQL > create or replace trigger register_trig before insert in the register for each line
    2 start
    3: new.create_time: = sysdate;
    4 end;
    5.

    Trigger created.

    SQL > insert into values of registry (no_registre) (1);

    1 line of creation.

    SQL > select * from registry;

    NO_REGISTRE CREATE_TI
    ----------- ---------
    1 8 JULY 13

  • active sessions for the global temporary table

    Hello

    Is there no view or the way to know how many active users evaluate a global temporary table?

    Rgds,
    Piyush

    The following query should list the user accounts writing (with INSERT/UPDATE/DELETE) into the temporary table 'TWG' belonged to "O":

    select s.username, l.sid
    from v$lock l, v$session s
    where l.id1 =
    (select object_id from dba_objects where owner='O' and object_name='GTT')
    and l.sid = s.sid;
    

    The following query should list all user accounts by using the temporary table named "GTT" with SELECT/INSERT/UPDATE/DELETE statement:

    select username
    from v$session s, v$access a
    where s.sid = a.sid
    and object ='GTT';
    

    Edited by: P. Forstmann on June 9, 2010 09:40

  • order of the lines of the global temporary table

    I have a global temporary table "TMP_PAYMENT_ANNUITY" and I insert records in there with loop for each iteration of loop insert a row in the table.
    Now, I'm back records inserted user with cursor in this way:
       open o_annuity_payments for 
          select * from TMP_PAYMENT_ANNUITY;
    Can I be sure that the slider will have records in exactly the same order as inserted loop them?
    Or do I also insert rownumber column of my table that I filled with the loop iteration variable, and I'll be back slider like this:
       open o_annuity_payments for 
          select * from TMP_PAYMENT_ANNUITY
           order by ROWNUMBER;
    Currently, I have "ROWNUMBER"-column in the table, but maybe I should create then? ".
    The question is about the order of the rows, how this order will be without "in order to" - clause?

    Published by: CharlesRoos on June 2, 2010 03:03

    CharlesRoos wrote:
    >
    What makes the solution of the temporary table better?
    >

    1. This approach/solution is easier to read for other developers. Ugly hierarchical query with the function LAG is difficult to read and edit.

    I agree with you! It's one of the reasons when you should stop developing very sophisticated SQL statements. Even if the performance is slightly better.

    2-hierarchical-feature in sql is always slow and friendly error.

    I don't think that a hierarchical solution is necessary. but it may depend on your version of Oracle (think MODEL clause).

    3. it is easy to implement the "temporary table solution." with complex sql construction will be time-consuming and bug-friendly and complex.
    3. I'm not sure the question of perfomance, here I may be wrong, I test/compare.

    ...

    CharlesRoos wrote:
    1 can someone confirm that I don't need "ORDER byclause?

    I never would implement it WITHOUT a prescription by cluase. Why depend on such a solution?
    One of your strong points would improve maintainability. It is against this requirement.
    Imagine this happening, for example, when another developer decided to move from a temporary to a normal table. Maybe by adding a field 'user '.
    In such a scenario, you can find ways where the output is sorted not more properly.

    I can't find Google evidence.

    2. what happens if I order by as:

    select * from TMP_PAYMENT_ANNUITY
    ORDER BY ROWID;
    

    This approach maybe gives me the order of the rows as they are in the table?

    main problem is that you cannot test if it STILL works without order. But you will need to find not only one rare case that breaks it.

    * In a multiuser environment, the table could put a few lines where another session comes to delete certain lines. This could influence the agenda.
    * oracle could change something for the release of "like orders ' (I did they did already in the GROUP BY clause from 9i to 10g).

  • How can I write the data on the graph xy

    I want to write the values of x and y... how can do that... I tried with the independent cluster.but the sons weren't told connected.it that the dimensions are not same.why my watch 3 xy dimenssional table? He must have a 2d painting.

    can someone help me please...

    Ignatius

    Normal, 'Write on worksheet File.vi' required a simple table 1 d or 2D as input and not a specific type in the cluster (because the XY graph is a cluster).

    So, given that your [X] data is the same for every [Y], you could build a 2D data table to use (by implementing the 'build picture' with [X] & [Y]).

    If it is not the case (same [X] for all [Y]), you will have to proceed to another method-online 2 files or the conversion of custom text before writing.

  • How can I write the SQL query for this requirement?

    Hello

    I have a table that looks like this:

    NAME | ANNUAL |     VALUE
    ==== | ====== | =====
    execno |     480.     000004
    step |      480.     0400
    SCNA |     480. cd_demo
    System |     480.     D47-010
    type |     480.     step
    free_text |     480.     stage 400
    rbare |     480.     RBA-1
    execno |     482. 000004
    SCNA |     482. cd_demo
    System |     482.     D47-010
    free_text |     482.     step 300
    step |          482.          0300
    type |      482.     step
    rbare |     482.     RBA-1
    execno |     483.     000001
    type |     483.     step
    rbare |     483.     rke1
    SCNA |     483.     rke10
    step |     483.     0240

    Now, say that I want to fetch ONLY annual with execno = '000004' and '400' = step and scna = "cd_demo" and system = "d47-010' and type = 'step', how to write SQL code?
    At first, it seemed like a simple writing query but I've been struggling with it for hours without success. I must admit though that I'm not strong in SQL :-)
    There, can anyone help? Please...

    Thanks in advance.

    Emmanuel

    Published by: user12138559 on October 30, 2009 03:05

    Hi, Emmanuel.

    Welcome to the forum!

    Here's a way to do what you asked:

    SELECT       doc_id
    FROM       table_x
    GROUP BY  doc_id
    HAVING       SUM (CASE WHEN name = 'execno' AND value = '000004'  THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'step'   AND value = '400'     THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'scna'   AND value = 'cd_demo' THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'system' AND value = 'd47-010' THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'type'   AND value = 'step'    THEN 1 END) > 0
    ;
    

    If you think that a WHERE clause would be used, but WHERE does apply to a single line. You need a condition that checks several rows in the same group.
    WHEN has an effect something like WHERE.

    Published by: Frank Kulash, October 30, 2009 06:26

    This solution assumes that (name, annual) is unique.

  • How can I write the SQL for this result?

    Hello my dear,
    Here first of all the script.
    CREATE TABLE ACC_TEST(
    AD_ID NUMBER,
    AD_NAME VARCHAR2(50),
    AD_SPM_ID NUMBER);
    /
    the data are
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (136,'Saleh Ahmed',129);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (142,'Hamidur Rahman',136);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (124,'Jasim Uddin',null);
    INSERT INTO ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) VALUES (129,'Sazib',124);
    I need the following result, when passing a value of Ad_Id. For example I go to 142 then result must be
    Select Ad_Id,Ad_Name
    From..
    ...
    where ad_id=142
    
    Ad_Id   Ad_Name
    136     Saleh Ahmed
    129     Sazib
    124     Jasim Uddin
    
    If I Pass Ad_Id=136 Then Result Should Be
    Ad_Id   Ad_Name
    129     Sazib
    124     Jasim Uddin
    
    
    If I Pass Ad_Id=129 Then Result Should Be
    Ad_Id   Ad_Name
    124     Jasim Uddin 
    Database 10 G XE

    Any help will be useful

    Hello

    HamidHelal wrote:
    WoW! You are totally my point. How do you understand that? l

    Guess luck. Guessing is generally not the best way to solve problems. It is generally faster and more reliable to say exactly what you want, as well as give an example.

    fallen little more that I want to know, if I want to restrict the output not more then 2, which would be sql?

    Now, you're not even giving for example!
    Maybe you want something like this:

    SELECT     ad_id
    ,     ad_name
    FROM     acc_test
    WHERE     LEVEL     BETWEEN 2 AND 3          -- Changed
    START WITH     ad_id     = :target_ad_id
    CONNECT BY     ad_id     = PRIOR ad_spm_id
    ;
    

    which will show just the mother and grandmother of the given line.

    I work with the developer of forms a lot. Knowledge of SQL is like sql oracle (9i cerfitication) book. But this type of sql is not available here.
    where can I learn this type of sql? SQL different then regular?

    Certification is another matter entirely.
    There are books and web sites dealing with more advanced techniques. Sorry, I don't know any good enough to recommend. Some authors (such as Tom Kyte) are always good.

    Here are a few sites that explain CONNECT BY queries:
    http://www.adp-GmbH.ch/ora/SQL/connect_by.html
    http://www.oradev.com/connect_by.jsp

  • How can I write the symbol ' greater than or equal to "in a string or a label?

    Hello

    I tried to use the "symbol" font to create the greater or equal symbol, but it does not work.

    Does anyone know how to do this?

    Thank you

    User

    The only way I know to do, is to type in the appropriate character code (Alt-0179, using the keypad), then highlighting the unique character (in most fonts, it is the exponent 3), then change the font to "symbol".  The rest of the characters in the string will be in the same font as before, only the highlighted character will change.

  • Add an attribute of the element configuration table type programmatically.  How can I specify the type of table?

    I am trying to add a configuration item that is an array of strings.  I don't know how to do this programmatically and have it show as an array of strings.  I would like people to be able to use the client of vCO and only change these if needed is.  I managed to add items, but they appear as "modified".  I can retrieve all ok by programming, but I guess since one can table actually waiting variant values is done deal as the generic object rather than an array of strings.  Is it possible to force this type when I put the value via the api?  It's my test code:

    var testArray = new Array();
    testArray.push ("string1");
    testArray.push ("string2");
    element.setAttributeWithKey ("TestKey", testArray);
    This translates into an attribute of type table, but I like it to be of type Array/string;

    Paul, as far as I know, you must manually set your attribute types using the vCO client. You cannot specify the types using script.

  • Table names are stored in a separate table; How can I use the domain as table name?

    Dear Experts,

    My version of oracle is,

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    PL/SQL Release 9.2.0.1.0 - Production

    CORE 9.2.0.1.0-Production

    AMT for 32-bit Windows: Version 9.2.0.1.0 - Production

    NLSRTL Version 9.2.0.1.0 - Production

    I stored the table names in a separate table as

    Table name: all_table

    Fields are: table_id, table_name, desc

    record of the sample: 1, EMP, EMPLOYMENT DETAILS

    Now I want to select all the contents of a perticular table, his name is all_table.

    (ie)

    Select * from (select table_name from all_table where table_id = 1);

    But it is not listing the details of the EMP table.  Its poster simply the name of the field "EMP".

    Please help me in this regard.

    Hello

    Whenever you make dynamic SQL statements, you must place the dynamic whole statement in a single string variable.  When debugging, display this string before running it.  If you get a runtime error that will show you the statement he makes, which often made the obvious cause.  For example:

    DECLARE

    CURSOR c IS

    SELECT table_name

    From user_tables;

    CNT NUMBER;

    sql_txt VARCHAR2 (1000);

    BEGIN

    FOR ut IN t

    LOOP

    sql_txt: = 'SELECT COUNT (*).

    || « DE » ' || t.table_name | '"';

    dbms_output.put_line (sql_txt |) "= sql_txt"); -For debugging

    EXECUTE IMMEDIATE sql_txt INTO cnt;

    dbms_output.put_line (' Table: ')

    || t.table_name

    || ' ('

    || CNT

    || "lines)"

    );

    END LOOP;

    END;

    /

    You can comment the put_line extra call when you are convinced that sylvie statement works.

    If you have non-standard table names (for example, names that contain spaces) you must place the names of the tables in double - quotes, as I did above.

  • Small request help on the use of the global temporary table - some doubts


    Hi all

    Few days back according to a condition, I used a TWG (on the ranks of commit preserve).

    I created a trigger (before the insertion of line level) on GTT that calls a procedure (pragma autonomous transaction declared in the procedure).

    Procedure inserts data into two tables and I have a validation final (after the two insertion of data in tables) in the procedure.

    I tested by inserting the number of lines in TWG and found that the two tables are correctly supply procedure called by trigger.

    Which means that my works absolutely perfect functionality. (performance is also good)

    Now, my question is: since in the production source ETL tool will load this TWG.

    ETL will use this table in different processes simultaneously.

    Suppose that a single session ETL populates this table, and at the same time in parallel another session fills this table with different data. is there a lock on this TWG?

    Would the TWG is blocking other lines to add at any time?

    Is it possible that data may disappear without completing the entire process prematurely TWG?

    PS the feature I developed is the generic exception feature. This works for all valid tables for the database. For most of the tables will be filled with ETL, that's why I had these doubts in my mind.

    I apologize, if these seems like childish doubts.

    Thank you very much

    Arpit Agrawal

    Each line I'll get my GTT and follow all the features [trigger procedure &], will be considered as a session until the validation, right?

    This is not correct, a session is considered between the opening of session (session is created) and close the session (session is closed) of the database.

    If I use, validation TWG deletions here, how would he had differed on commit preserve as when my feature is completed, I don't want to keep more data.

    If on commit delete has been used here, it wouldn't make a difference in your case since you make is ENGAGING in some AUTONOMOUS OPERATIONS.

    In both cases, commit delete and commit preserve, you don't have to worry about the data inside the TWG because it will be empty onece you logoff (session ends).

    However, you can perform a delete operation in your session if you do not want to keep the data up to the end of the session.

  • How to query other session data in a global temporary table

    Performance tune a sql statement that uses a table temporary overall (10g R2), it would be very useful that I could see the data of the TWG, which belongs to another session. Is this possible?

    I'm sure that's not possible. TWG are transaction or specific session data in it can be seen from the other sessions.

Maybe you are looking for