Create temporary table in the procedure

I have a procedure which can be called at any time by multiple users. So I cann't use table in there, because on each call, the table is truncated and inserted. How can I create a temporary table in the procedure?

Temporary tables in Oracle are different from other RDBMS like SQL Server.

In Oracle, you create a global temporary table ONCE as part of the design of your database.

create a global temporary table MyTableName (... columns...) on commit preserve rows;

You can then use this table in your code as you would any other table.

The difference is that any data that you insert in this table are only available/visible so that the code runs in the session, and if delete you / truncate the table it only removes the data for this session.  In this way, several sessions we can table without interfering with each other.

(Note: instead of "preserve" you can change this to "delete" If you want that deleted data automatically when a commit is issued in your session, otherwise the data will be automatically deleted at the end of the session)

Tags: Database

Similar Questions

  • How to create temporary tables in stored procedures.

    Hello

    I am new to oracle, I have a requirement where I need to run a query in a loop for different values of where condition. Here, I need to record the results of the query on each iteration. After the end of the loop, I need to send the results to the front end. I did a lot of research for the concept of the temporary table in oracle, but I found myself unresolved except headaches. Everyone is showing how to create temporary tables in general but not in stored procedure.

    Bad, I need the concept of temporary tables, or is there an alternative way to store temporary results. My procedure looks like this.

    create or replace
    procedure uspMatchCode (parWord varchar2, p_recorderSet to types.cursor_type)
    as
    smallint parCnt;
    Start
    parcnt: = 0;
    Select count (1) in parCnt of...;
    If parcnt > 0 then
    Open for P_recorderSet
    Select field1, field2, field3,... of table1, table2, table2 where < < condition > >
    on the other
    -Here, I want to create a temporary table and store the result for the loop shape into the temporary table.
    CREATE TEMPORARY TABLE global my_temp_table (NUMBER of Column1, Column2) ON COMMIT DELETE ROWS.
    FOR parCnt in 0.3
    loop
    INSERT into my_temp_table select Field1, Field2, field3,... from table1, table2, table2 where < < condition > >
    end loop;
    Open for P_recorderSet
    Select * from < < temporary table > >
    end if;
    end;

    Any help would be great to check me on the problem.

    Thank you
    Kiran.

    This is a change to the query Kiss has posted:

    with data_text like)
    Select regexp_substr (' sales financing marketing ',' [^] +', 1, level ") val
    of tconnect by level<= length('sales="" finance="" marketing')-="" length(replace('sales="" finance="" marketing','="">
    )
    Select * from t, data_text, where t.colname like '% "| data_text. Val |' %'

    This will help you. Please change the column names and the name of the table as a result

  • How to create a temporary table in a procedure.

    How to create a temporary table in a procedure.

    Hello

    user9093700 wrote:
    How to create a temporary table in a procedure.

    Why create a temporary table in a procedure?

    Oracle has soemthing called a global temporary Table , where the table is in fact permanent, but data is automatically deleted at the end of the session (or the transaction, depending on how the table was created). What did you talk about? Why do you want to create one in a procedure?

    Temporary tables, in the sense of the tables that are created on the fly and fell just as they are used, are almost never a good way to do anything in Oracle. Explain what you want to do, and someone will help you find a good way to do it.

    If you need really to create a table (or any other kind of DDL) in a procedure, use EXECUTE IMMEDIATE.

  • Dynamic temporary Table in stored procedure

    Dear expert,

    I'm trying to convert a database from MSSQL to Oracle 11 g. But I'm a little stuck on dynamic temporary tables in stored procedures.

    MS is normalize the data out dynamic SQL statements. In TSQL so I've created a Temp table with the number of columns that the SQL statement has, that I executed the SQL statement in the temporary table and then I was going to all the columns with the prompting separate command standard. Finally, I wrote the key table.

    If I want to do this process with only on SP, dynamic, rather than to define for each normalization process its own SP, so this possiple in Oracle?

    For example. "INSERT INTO Temp (PartNo, Descr, Type, price) SELECT PartNo, Descr, price from parts.

    PartNo. Descr | Type | Price
    AB00 | AKER GD245 | Monitor | 200.00
    AB01 | Samir QQ22 | Monitor | 120.00
    AQ05 | HB 5500DN | Printer | 550.00

    SELECT @R = Max (PartKey) of N_Parts
    INSERT INTO N_Parts (PartKey, PartNo) SELECT RowNum + @R, PartNo FROM (SELECT DISTINCT PartNo FROM Temp INCLUDING PartNo NOT IN (SELECT PartNo of N_Parts));
    SELECT @R = Max (PartDKey) of N_PartsDescr
    INSERT INTO N_PartsDescr (PartDKey, Descr) SELECT RowNum + @R, Descr FROM (SELECT DISTINCT Descr FROM Temp WHICH Desrc NOT IN (SELECT Desrc from N_Parts));
    ...

    Insert into Part_Data (PartKey, PartDKey, PartTKey, PartPKey)
    SELECT T0. PartKey, T1. PartDKey, T2. PartTKey, T3. Temp PartPKey T
    INNER JOIN N_Parts T0 to T0. PartNo = T.PartNo
    JOIN IN-HOUSE...

    So what is the best way, do not generate this dynamic Table Temp?

    Published by: 926165 on 08.04.2012 08:26

    926165 wrote:
    I'm trying to convert a database from MSSQL to Oracle 11 g. But I'm a little stuck on dynamic temporary tables in stored procedures.

    Just my 2 cents here.

    Conversion of database provider A to B of database provider is never really a great idea. The products are fundamentally different in many ways. Analysis of demand that needs to be ported from database at database B and then its implementation in a specific way to take advantage of the features of your new environment, accounting for all the differences between the implementations of provider will be your best bet.

    I say this because, for me at least, a conversion means that you take what you have and it in slam in what you need. The better approach is to analyse, design (to explain the differences in behavior between vendor implementations, such as mechanisms for read consistency) and proceed from there. This way, you have a solid base on which to start, instead of a skyscraper built out of toothpicks.

    See you soon,.

  • Temporary tables in stored procedure

    Hello

    I write a stored procedure that will get data from different sources and generates a spreadsheet finally. Initial selection gets the basic data and chooses then merges the data.

    To do this, I created a table in the database, I'm filling in data in this table by using the same procedure and finally selection of data in this table to generate the worksheet.

    Now, I plan to use the TEMPORARY table instead of create database table. Can someone tell me where I can watch examples for temporary tables?

    What is the best option in performance wise?

    or

    I can handle the whole scenario with slider? examples?

    Hello

    Why you cannot use an ordinary table?

    Search for [Global Temporary | http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#sthref7247] in the diocumentation, including SQL * manual language, an alternative.

    'Temporary' applies only to the data. A global temporary Table is created once and remains until you DROP, the same as any other table.
    The data in the table are temporary. If you create the table by saying "ON COMMIT PRESERVE ROWS" (which seems appropriate, according to your description) the data will be automatically deleted when you end the session database.

    All global data in temporary Tables are specific to the session. If two (or more) people use the same table at the same time, each one will see data that they inserted themselves; they'll never see rows inserted by the other session.

    Almost everything you can do with an ordinary table, you can do with a global temporary Table. In particular, DML (such as FUSION) and cursors work exactly as they do on other tables.

  • : SQL error create temporary table

    I do a small Forum of discussion for a customer.

    So having a problem below:

    Internal error.
    tNG_fields.getFakeRecordset:
    SQL error: error creating temporary table:
    Você tem um erro syntax no seu proximo a SQL '-TEXT messaging, cidade idade foto senha, TEXT TEXT TEXT TEXT of COD)' na linha 1
    SQL:
    CREATE TEMPORARY TABLE KT_fakeRS_20090928 (nome cidade of TEXT, text, TEXT, TEXT, TEXT, TEXT, TEXT of cod senha foto idade) (FIELDS_FAKE_RS_ERROR)
    • tNG_insert.executeTransaction
      • STARTER. Trigger_Default_Starter
    • tNG_insert.getRecordset
    • tNG_insert.getLocalRecordset
    • tNG_insert.getFakeRecordset*


    Please help me solve this problem.



    Can´t you have the hyphen (-) in the column names and that s why MySQL chokes on the column 'email '. That said, please rename this column 'e-mail' or 'email' (underscores are allowed)

    See you soon,.

    Günter

  • Get the 500 error trying to create a table using the REST API

    Hello

    I tried to create a table using the REST API for Business Intelligence Cloud, but I got 500 Internal Server Error for a while now.

    Here are the details that I use to create a table.

    Capture.JPG

    and the json to create the schema that I use is

    [{'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ["ROWID"]}]

    , {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['RELATIONID']},

    {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['ID']}

    , {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['RESPONDEDDATE']},

    {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [255], 'columnName': ['RESPONSE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_CREATEDDATE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['SYS_CREATEDBYID']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_LASTMODIFIEDDATE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['SYS_LASTMODIFIEDBYID']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_SYSTEMMODSTAMP']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [10], 'columnName': ['SYS_ISDELETED']},

    [{'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [50], 'columnName': ['TYPE']}]

    I tried this using postman and code, but I always get the following response error:

    Error 500 - Internal server error

    Of RFC 2068 Hypertext Transfer Protocol - HTTP/1.1:

    10.5.1 500 internal Server Error

    The server encountered an unexpected condition which prevented him from meeting the demand.

    I am able to 'get' existing table schemas, delete the tables, but I'm not able to make put them and post operations. Can someone help me to identify the problem, if there is no fault in my approach.

    Thank you

    Romaric

    I managed to create a table successfully using the API - the only thing I see in your JSON which is different from mine is that you have square brackets around your values JSON where I have not. Here is my CURL request and extract my JSON file (named createtable.txt in the same directory as my CURL executable):

    curl u [email protected]: password UPDATED h x ' X-ID-TENANT-NAME: tenantname ' h ' Content-Type: application/json '-binary data @createtable.txt https://businessintell-tenantname.analytics.us2.oraclecloud.com/dataload/v1/tables/TABLE_TO_CREATE k

    [

    {

    'columnName': 'ID',

    'dataType': 'DECIMAL ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': false

    },

    {

    'columnName': 'NAME',

    'dataType': 'VARCHAR ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    "columnName': 'STATUS."

    'dataType': 'VARCHAR ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    "columnName': 'CREATED_DATE."

    'dataType': 'TIMESTAMP '.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    'columnName': 'UPDATED_DATE ',.

    'dataType': 'TIMESTAMP '.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    }

    ]

  • need a script to create multiple tables as the other columns in tables

    I need script to create multiple tables as the other columns of tables respectively.

    lets consider I want to create tables from table1... table99 like tablex1... .tablex99 columns (without data) respectively (i.e table1 as tablex1, table99 as tablex99).
    declare
    
    cursor c is select object_name from all_objects where object_type='TABLE';
    
    begin
    
    for i in c loop
    
    execute immediate 'create table '||i.object_name||'_x as select * from '||i.object_name||' where 1=2';
    
    end loop;
    
    end;
    
    use can use this and put your user names accordingly.
    If you get any error please post the error.
    
  • "missing the SELECT keyword" error during an insert into the temporary table using the blob value

    I'm trying to insert into an oracle temp table using select that retrieves data from a blob field but I get the error: "lack the SELECT keyword.

    How we store temporary in oracle result when we make this type of operation (extraction of data in fields and try to load them into a separate table on the fly.?)

    with cte as)

    Select user_id, utl_raw.cast_to_varchar2 (dbms_lob.substr (PREFERENCES)) as USER my_blob

    )

    create table new_table as

    SELECT user_id,EXTRACTvalue(xmltype(e.my_blob),'/preferences/locale') regional settings

    E ETC

    ----------------------------------------------------------------------------------

    BLOB data - value - which is

    <? XML version = "1.0" encoding = "ISO-8859-1" ?>

    - < Preferences >

    < time zone > America/New_York < / > zone

    < displayscheduleinusertimezone > Y < / displayscheduleinusertimezone >

    < local > Spanish < /locale >

    < DateFormat > JJ/mm/aaaa < / DateFormat >

    < timeFormat > hh: mm aaa < / timeFormat >

    < longformat > Long_01 < / longformat >

    < doubleformat > Double_01 < / doubleformat >

    < percentformat > Percentage_01 < / percentformat >

    < currencyformat > Currency_01 < / currencyformat >

    < / Preferences >

    A WITH clause that must immediately precede the SELECT keyword:

    SQL > create table t:

    2 with the o as (select double dummy)

    3 select * West longitude;

    Table created.

  • Implementation of associative array (indexes per Table) in the procedure

    Hi guys,.

    I'm trying to implement collections in the procedure. I am trying to store integer values as well as the names & to print the same list of names. Here is my procedure

    create or replace procedure (coll_proc)

    )

    is

    pay type is table of the index number to varchar2 (20);

    salary_list salary;

    L_Name varchar2 (2000);

    Start

    salary_list ('Aude'): = 62000.

    salary_list ("Mohammed"): = 50000;

    ("Julian") salary_list: = 45000;

    L_Name: = salary_list.first;

    l_name is not null loop

    dbms_output.put_line (' the wages of ' |) L_Name | « est » ||' ='|| TO_CHAR (salary_list (L_Name)));

    L_Name: = salary_list. Next (L_Name);

    end loop;

    end;

    Below is the error

    "Error (2.1): PLS-00103: encountered the symbol") "when expecting one of the following numbers: Remove current exists prior" "

    You people could please check this & tell me that where I'm going wrong.

    Hello

    It seems that you have all the parameters in your stored procedure, so remove the "()" after the name of the procedure.

    create or replace procedure coll_proc
    is
      type salary is table of number index by varchar2(20);
      salary_list salary;
      l_name varchar2(2000);
    begin
      salary_list('Rajnish'):=62000;
      salary_list('Minakshi'):=50000;
      salary_list('Seetha'):=45000;
    
      l_name:= salary_list.first;
      while l_name is not null loop
        dbms_output.put_line('Salary of ' ||l_name|| 'is'||'='|| to_char(salary_list(l_name)));
        l_name:=salary_list.next(l_name);
      end loop;
      end;
    

    I tried this and able to create the procedure

    Procedure created.
    

    Kind regards

    Jitendra

  • How can I create a table of the "party" or code

    Hello

    I still have some problem of thought on my code and how I had to do. (Newbie here! )

    The question is that I want to create a member code of the 'Party' for 10 heroes or more with all the separate stats.

    I wonder if I should create a table that I send across or there is another solution, like a temporary file which stock upward and save.

    The table should look like this:

    LVL 1 of table: part of article

    LVL 2 of table: name, attack, defense, xp lvl of the character.

    Example: [["rodolf", 1300, 3, 4, 78], ['Tak', 1301, 4, 3, 79], ["mukmuk", 80, 103, 2, 3], etc...]

    I know that I can blow up when a character matrix or leave the party, but I think that's not a good solution for this. The party is a very active variable and can change many times. So I need your help to guide me! Please, I beg you!

    Please read my problem and try to help me!

    Use an object:

    var obj:Object = {};

    updateParty('rudolf',1300,3,4,78);

    function updateParty(nameS:String,_xp:int,_attack:int,_defense:int,_lvl:int):void {}

    obj [names] = {attack: _attack, xp:_xp, lvl:_lvl, defence: _defense};

    }

    function retrieveParty (names): object {}

    return items [names];

    }

    ///////////////

    so if you want to recover the mukmuk lvl, use:

    trace (retrieveParty('mukmuk'). LVL);

  • How to create a package with the procedures?

    Referring by the net, I've written the following PCK file. I installed my Oracle database 11g in VirtualBox (Win XP). I can able to select tables using the query from the host (Windows 7)

    CREATE OR REPLACE PACKAGE APEX_SYS_PCK

    AS

    TYPE refcursortype IS REF cursor

    PROCEDURE GET_USER_DETAILS)

    D1 ON refcursortype,

    P_USER IN VARCHAR2,

    P_PASS IN VARCHAR2);

    END APEX_SYS_PCK;

    /

    CREATE OR REPLACE PACKAGE BODY APEX_SYS_PCK

    AS

    PROCEDURE GET_USER_DETAILS)

    D1 ON refcursortype,

    P_USER IN VARCHAR2,

    P_PASS IN VARCHAR2)

    IS BEGIN

    OPEN D1 FOR SELECT * FROM APEX. PEOPLE;

    END GET_USER_DETAILS;

    END APEX_SYS_PCK;

    /

    When I try to run the script, I get the following error. How to solve this problem? If there is an error in this package please correct!

    • Project: sqldev.temp:/IdeConnections%23vAPEX.jpr
    • F:\PACKAGES\APEX_SYS_PCK. SQL
    • Error: PL/SQL: analysis of completed Compilation unit
    • Error (1.14): PLS-00905: APEX oppose. APEX_SYS_PCK is not valid
    • Error (1.14): PLS-00304: impossible to compile 'APEX_SYS_PCK' body without its specification

    You are missing a semicolon after

    TYPE refcursortype IS REF cursor

    in the specifications of your package.

  • create temporary table

    Any syntax error in the code below?


    CREATE a TEMPORARY TABLE GLOBAL OWN.TT_tmp
    Did YOU SELECT distinct ssm_id, CAP.position pricing
    ON COMMIT PRESERVE ROWS;

    Error report:
    SQL error: ORA-00933: SQL not correctly completed command
    00933 00000 - "not correctly completed SQL command.
    * Cause:
    * Action:

    Hello
    Yes, there is a syntax error

    CREATE a TEMPORARY TABLE GLOBAL OWN.TT_tmp
    ON THE LINES OF COMMIT PRESERVE
    Did YOU SELECT distinct ssm_id, CAP.position pricing;

    Kind regards
    Simma...

  • Creating external Tables using the EXECUTE IMMEDIATE in PL/SQL

    Hi guys,.

    I am trying to create an external Table using the EXECUTE IMMEDIATE in a procedure and I managed to compile and no errors were generated. But when I try to run it from sql using the exec command I get the following error:

    ------------------------------------------------------------------------
    ERROR on line 5:
    ORA-00911: invalid character
    ORA-06512: at "GEO. TEST_DDL', line 4
    ORA-06512: at line 5

    -------------------------------------------------------------------------

    I tried to check the whole statement to create the external table, but I can't find where is the error. Surprisingly, if I simply run the command table create external on sqlplus it works, but not a procedure.

    If anyone can help with ideas or experience?

    Geoffrey Kossami

    The error means that there is an identifier somewhere that starts with a nonalphanumeric. This is a typical mistake of editing. A procedure compiles correctly is not of course because the underlying dynamic sql running is OK. Which of course only be resolved when you try to run it.

    There is certainly a problem with the text you provide to be run as a piece of dynamic sql code. You should try to watch it with dbms_output and run this code in sqlplus. But your problem is with the code you run as dynamic PL/SQL, it is not itself compilable.

    Jack

  • Using numbers to create a table where the value of the line increases automatically

    Hello

    I created a table (pictured below) to help calculate my self-employed income:

    INDEX

    DATE

    HAVING RETURNED TO THE SELF-EMPLOYED

    £

    A1

    I want to create an index / of reference for each line so that I can connect to receipts.

    I like the index / reference to automatically increase i.e. A2, A3 etc when I create a new line by using the shortcut 'alt - cursor down' but to note has managed to find out what formula to use.

    Any help would be great!

    Thank you very much

    Stophen.

    You can try something like this:

    = 'A' & rangee()

    SG

Maybe you are looking for