SELECT the data inserted into a global temporary Table in a stored proc

A stored procedure is run from Oracle SQL Developer to insert data into a global temporary table. A SQL (in Oracle SQL Developer) worksheet is open to run a SELECT query to retrieve the data from the temporary table overall which was populated in the stored procedure. No row is returned. I guess it's because the stored procedure and the SELECT statement executed in different sessions.

Is it possible to run the stored procedure in Oracle SQL Developer and then execute a select statement on the temporary table overall which was filled in the stored procedure by using the same connection so that the data can be extracted?

I use version 1.5.1 build HAND-5440 of Oracle SQL Developer.

In a worksheet, do something like

Start
insert_proc;
end;

Select * from my_temp_table;

Place the cursor on each statement in turn and Press f9 (where it all began... the end is a single statement.

Tags: Database

Similar Questions

  • Global temporary tables in a stored Proc

    Hi all

    I am trying to create a procedure that creates tables, and then global temporoay tables. This works well in a scrupt but when I place it in a proc, it fails with the following error

    Error (172,10): PLS-00103: encountered the symbol "TABLE" when awaits one of the following values: =. ( @ % ;


    I use the code below to create global temporary tables, but I don't think that you can do in a procedure?

    TRUNCATE TABLE TMP_table;
    DROP TABLE TMP_table;
    CREATE GLOBAL TEMPORARY TMP_table
    ON THE LINES OF COMMIT PRESERVE
    IN SELECT

    Thanks for any help

    You cannot use dll phrases in a Begin End; block directly.

    Yun can use something like

    Begin
    Execute immediate 'TRUNCATE TABLE TMP_table';
    Execute immediate 'DROP TABLE TMP_table';
    Execute immediate 'CREATE GLOBAL TEMPORARY TMP_table ON COMMIT PRESERVE ROWS AS SELECT ';
    End;
    
  • How to insert into a GLOBAL TEMPORARY TABLE and get the data from it?

    The requrement is
    Split the string ENTRY point on the base and store it in a Collection. And the values of the collection will be stored in a global temporary table. Then, I'm updating some other table based on the data from the temporary table.

    There is in fact no error message. But there is no data in the temporary table and also no change in the update statement

    First of all, I'm creatiing a global temporary table only once outside the procedure.

    CREATE GLOBAL TEMPORARY table GLt (data_element number)


    create or replace procedure test_proc (p_in_string VARCHAR2) is
    i the number: = 0;
    number of POS: = 0;
    CLOB lv_str: = p_in_string;
    p_delim VARCHAR2 (1): = ', ';

    TYPE t_array IS TABLE OF VARCHAR2 (20) INDEX directory.
    t_array channels;

    BEGIN

    -cutting of string input and store in the strings (i) collection

    POS: = instr (lv_str, p_delim, 1, 1);
    WHILE (pos! = 0) LOOP
    i: = i + 1;
    Strings (i): = substr(lv_str,1,pos-1);
    lv_str: = substr (lv_str, pos + 1, length (lv_str));
    POS: = instr (lv_str, p_delim, 1, 1);
    IF pos = 0 THEN
    Strings (i + 1): = lv_str;
    END IF;
    END LOOP;

    run immediately "drop table TWG;
    run immediately ' CREATE GLOBAL TEMPORARY table (data_element number) TWG on commit preserve rows ";

    FORALL i in strings.first... Strings.Last
    INSERT INTO VALUES TWG (strings (i));
    commit;

    Update first_tbl set PIN is "XXX" where first_col in (select data_element from TWG);.
    commit;

    END test_proc;

    Published by: cedric b on January 25, 2013 12:59

    Remove the two execute immediate line. They are wrong.

    And then use the table in your code that you created at the beginning. The name is GLT.
    And delete the first commit. This validation would empty the temporary table of GLT.

    You get an error? Or it does not work as expected?

    Also, show how you call the procedure.

    Published by: Sven w. January 25, 2013 14:45

  • What is the syntax for creating a global temporary table using a select query

    HII
    I create a global temporary table using a select query... How to speak of "on commit preserve rows ' who?


    create a table temporary global t1 select * from trn_ordbase on the lines of commit preserve;

    but this is an invalid syntax, then how to talk on commit preserve rows in this? If I don't mention, by default its recital on the validation of deleted rows.

    Please help me on this problem.
    create global temporary table t1 on commit preserve rows
      2  as select * from dual;
    
    Table created.
    
    TUBBY_TUBBZ?
    
  • What is the best (global temporary Table or tables of Type Object)

    Dear all,

    I'll try to refine some code and find that we have a large loop that goes to loop over 100000 times and for each record, it in turn for validation of controls in individual tables.

    I intend to implement all of the functionality of controls using join conditions. I.e. to empty all the data into a global temporary table or tables oracle object type and apply the conditions of verification using join operations, so that I can avoid the unnecessary check for each record.

    If I want to implement this, I want to know what is best. A global temporary table or the Oracle Tables nested.

    Appreciate your response.

    Thank you
    MK.

    If you mean a global temporary table vs a variable from PL/SQL grouping, then 100 + lines is a lot to store in session memory a GTT would be so a more scalable solution. It will give you more options to manipulate the data using SQL.

    Note that a 'table of type object', or 'table object type' can mean a table of database (no PL/SQL) for example "CREATE TABLE MyTable mytype". However, I don't think you mean that.

  • Global Temporary Tables and truncate

    Hi all

    I have SQL script like this. Firstly, it truncates the Temp_emp and then, it will load data from big_table.
    Whenever I run this script from the SQL prompt, the data inserted into the Temp_emp are doubled. What can be the reason. Am I missing something
    concert of temporary Tables and global Truncate?

    *. SQL file starts here *.

    BEGIN
    RUN IMMEDIATELY 'TRUNCATE TABLE Temp_emp;
    END;
    /

    INSERT INTO Temp_Temp
    SELECT col1, col2, col3, col4 col5
    Of
    (SELECT col1, col2, col3, col4 col5 FROM big_table bt
    WHERE bt. ROWID IN (SELECT MAX (ROWID) FROM big_table
    GROUP BY col1, col2)
    ) ;

    /

    *. SQL file ends here *.

    Thanks in advance,
    PAL

    Please remove the "/" after the insert in your sql script. It executes the same statement insert again. Therefore, the data are doubled.

  • Are global temporary tables, a standard feature of Oracle?

    I apologize for introducing me to this community with what must seem like a very stupid question...

    I am a software developer, working on a product that uses Oracle as its database, specifically Oracle 11 g Enterprise Edition. Recently, I solved a problem of performance by converting an ordinary table into a global temporary table. Before my boss allows me to put this change in the product, it wants to be sure that global temporary tables are a standard part of Oracle, not something that the customer must install separately or pay extra for. (This is the first time that we never used them in our product, so I think that most of the team are not familiar with them).

    I know that Oracle has had global temporary tables since the last millennium, so if ever, they have been a feature of the premium, they are unlikely to be now, but the boss wants me to get independent confirmation of this.

    Thank you.

    Steve Pemberton

    Here you can see "feature availability by Edition":

    http://docs.Oracle.com/CD/E11882_01/license.112/e47877/editions.htm#DBLIC116

    TWG tables is not even mentioned, which means that they do not belong to the functional components are paid separately.

    One caveat - if you have an application that uses connection pooling, it is recommended to use ON COMMIT DELETE ROWS, not ON COMMIT PRESERVE ROWS

    (or always use explicitly "DELETE gtt_table" at the beginning), because otherwise a user of the application can display the data TWG who has previously made a second user of the application.

    Kind regards

    Zlatko

  • Global temporary table Vs Table permanently to manipulate the transaction data

    Hi all

    Version of database - 10.2.0.4

    We need handle transactions, data in a table and put in an intermediate table (ie): to replicate the data in the tables of a schema of staging of the tables in the schema. Get info on transactions and handling.
    Can you please indicate which one of the below is the best option.

    Option 1:
    Create a global temporary table, each running process.

    Option 2:
    Create a table permanently and delete lines at the beginning of the process.

    Job expects every 5 minutes

    Thank you and best regards,
    Rakesh

    If data are transient and must be written to the disk (I'm not sure I follow your explanation for why written data on the disk are necessary - you have to touch table large transaction each time to fill the intermediate table) using a global temporary table. At least, you'll reduce the cost of writing the data to disk by generating less recovery.

    But ideally, you would not write the data on the drive at all and would be able to do it in SQL.

    Justin

  • 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

  • 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

  • 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

  • Select the data in a table and update in another table

    Dear experts,

    create the table TB_ENCRYPT

    (

    Identification number,

    Varchar2 (200) KEY

    );

    INSERT INTO TB_ENCRYPT VALUES(1,'HJUVHDUIFBSDGVU');

    SELECT * FROM TB_ENCRYPT;

    1 HJUVHDUIFBSDGVU

    create TABLE users)

    username, NUMBER of

    password VARCHAR2 (200)

    );

    Insert users

    values (1, 123 # "")

    Insert users

    values (2, 456 #')

    Select * from users;

    1 123 #.

    # 2 456

    I want to select the data KEY for table TB_ENCRYPT column and update in the column of tables for the respective key user password

    TB_ENCRYPT table contains only a single key value. Comparing this key, I want to update the old value of the key to the new value.

    For encryption and decryption I followed the java class method.no is worried about that.

    create or replace

    PACKAGE PCK_ENC AUTHID CURRENT_USER AS

    FUNCTION DECRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.decrypt (java.lang.String, java.lang.String) return java.lang.String ';

    FUNCTION ENCRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.encrypt (java.lang.String, java.lang.String) return java.lang.String ';

    END;

    SELECT PCK_ENC. ENCRYPT('1234','HJUVHDUIFBSDGVU') FROM DUAL;

    HERE,

    1234 - is the password of the users table column data

    HJUVHDUIFBSDGVU - represents the key of table TB_ENCRYPT column data.

    Comparing this key, I want to update the old value of the key to the new value.

    I tried with this method

    declare

    cursor c1 is

    Select the key

    of TB_ENCRYPT

    where id = 1

    update the id;

    Start

    for c1_rec looping c1

    update users

    password is PCK_ENC. Encrypt (Password, Key)

    the location being c1;

    commit;

    end loop;

    end;

    /

    Help, please

    You can use the MERGE statement.

    merge into users
    using tb_encrypt
       on (id = userid)
      when matched then
          update set password = PCK_ENC.ENCRYPT(password,key);
    

    And why you encrypt your password. This isn't a good idea. Just password hash.

  • 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).

  • What to fill in 'field of the temporary table' for global temporary tables?

    Hello

    I use the Data Modeler 4.0.1.836 and everything that I put in the box 'the scope of the table temp' for a global temporary table doesn't seem to affect the DDL script about the ON COMMIT PRESERVE/DELETE the LINES option. The script poster ON COMMIT PRESERVE ROWS always anything.

    Yet, some of my temporary tables must be created as ON COMMIT DELETE ROWS.

    Using the Data Modeler wrote about it:

    Scope of the temporary Table:

    For a class as a temporary table, you can specify a scope, such as the Dimension or the Session.

    Not sure what 'Dimension' has to do with the scope here, but it makes no difference.

    I tried to put 'Session', 'Dimension', 'Operation', but no luck. So what is the text for the script generate ON COMMIT DELETE ROWS?

    Thank you

    Hello

    The temporary Scope of Table property (on page Types of Classification of the table properties dialog box) is purely documentary.

    To set ON COMMIT DELETE ROWS you must expand the browser for the relational model and find the node for the relevant Oracle physical model.  If you develop it you will find an entry there for your Table. Double-click on that to get the physical model properties dialog box for your table, and you will find a "Temporary" facility that has options (Preserve Rows), YES (Delete Rows) YES or no.

    David

  • Edit and a global temporary table

    Hi all

    Can someone tell me why when I create a TWG and insert the data as the followijng, I get insert 14 ranks msg. But when I do a select statement of the sqlwork shop, sometimes I get the data sometimes that I don't have. my understanding is that these data are supposed to stay during my session logon then got cleaned up when I left the session.
    I develop a screen in the apex and will use this temporary table for the user to perform editing work. Once Island edition done then I save the data in a static table. Is this possible? So far my every attempt to update that the temporary table always results in 0 rows updated in the temporary table and reversed to 0 lines. Can you help me?

    CREATE A GLOBAL TEMPORARY TABLE 'EMP_SESSION '.
    (SELECT "EMPNO" NUMBER NOT NULL,)
    'ENAME' VARCHAR2 (10),
    VARCHAR2 (9) "JOB."
    NUMBER OF "MGR."
    "HIREDATE" DATE,
    NUMBER OF "SAL."
    NUMBER OF THE "COMM"
    NUMBER OF "DEPTNO".
    ) ON COMMIT PRESERVE ROWS
    /

    insert into emp_session (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Select * from EMP
    --
    Select * from emp_session
    -Sometimes I 14 ranks, sometimes 0 rows

    Thank you.

    Tai

    APEX does NOT support the use of TWG... Use rather a collection to manipulate your temporary data... : http://www.dba-oracle.com/t_easy_html_db_collection.htm

    Thank you

    Tony Miller
    Webster, TX

Maybe you are looking for