Creating temp table within OPEN QUERY

I am having trouble in creating a temp table within my OPEN QUERY.
How do I modify the below script to do this?
declare @sql nvarchar(max)
set @sql =
'SELECT *
FROM audit.dbo.Comp AS a
INNER JOIN audit.dbo.Pat AS b ON b.key = a.key
AND b.reg = ''' + @id + '''
INNER JOIN [prod].nfegh.dbo.flTest AS c ON c.id COLLATE Latin1_General_CI_AS = b.reg
INNER JOIN (
SELECT ''M1Q'' UNION ALL
SELECT ''M0Q'' UNION ALL
SELECT ''S1N''
) AS f(x) ON f.x = CLIN
WHERE a.inv IN (''CR'', ''R'', ''EAT'')'
set @sql = N'select * into MS_test1
from openquery( ocles, ''' + replace (@sql , '''' , '''''') + ''' )'
exec (@sql)

OPENQUERY is designed to provide rows or to be user as target for DML.
But even when this statement would create a temporary table, then it would be out of scope.

Similar Messages

  • How to create Temp Table?

    Hi..
    I gotta output 2 table in my database. And, want to output
    all fields of such table in one grid. So, can I create temp table
    in Coldfusion MX7? Here is my table structure of two tables.
    table 1) Company_name, exp_Value
    table 2) Company_name, imp_Value
    I want to create temp table like
    temp table ) Company_name (table1 + table 2) , exp_value
    (table 1), imp_value (table 2)
    so, how can I solve this problem.?
    All solutions will be appreciated.
    best,
    Z

    (Z) wrote:
    >
    quote:
    Originally posted by:
    cf_dev2
    > Try using a FULL OUTER JOIN
    >
    > select coalesce(t1.Company_name, t2.Company_name) AS
    Company_name,
    > t1.exp_Value, t2.imp_Value
    > from table1 as t1 full outer join table2 as t2
    > on t1.Company_name = t2.Company_name
    >
    > Thanks, buddy. But, it's not ok for my project. Because,
    million of records
    > are in each tables. If I do so, page loading is really
    huge and cannot be
    > displayed within 10 seconds. Another solutions?
    >
    > All of solutions will be appreciated..
    >
    >
    >
    another solutions?
    well, what exactly are you trying to do if none of the
    solutions given
    so far work for you?
    i believe the suggested solutions covered all possibilities,
    save for
    UNION query, which, from what i can understand from your
    explanations,
    is NOT what you need either...
    if cf_dev2's OUTER JOIN suggestion is "not ok" for your
    project - i
    don't know which one will be "ok" then...
    how many records are you expecting in your "temp table" if
    not all
    records you have in the db? how can you expect fewer than all
    records if
    using INNER JOIN is not acceptable to you because "some
    company_names
    would be lost if table (1) company_name isn't included in
    table (2)"???
    you really should look at normalizing your db, i think...
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Temp Table within an Stored Procedure

    I'm pretty new to Oracle, but I have been developing in MS SQL for about 15. So I'm still getting use to the syntax and features within Oracle.
    I'm trying to create a stored procedure that has two temporary tables within it, and then queries both them tables and inserts the results into a table.
    I created the script but when they try to run in on the server it wont run. Can you guys tell me what I'm doing wrong?
    CREATE OR REPLACE PROCEDURE UpdateFIDB_SP IS BEGIN               CREATE GLOBAL TEMPORARY TABLE myAAAA         AS               (SELECT  AAAA.1111, AAAA.2222, BBBB.3333_EXT, CCCC.4444, DDDD.5555, DDDD.6666, DDDD.7777,                       DDDD.8888, AAAA.9999, EEEE.1010, EEEE.1A1A, EEEE.1B1B, FFFF.3333_LO, FFFF.1C1C,                       AAAA.1D1D               FROM mySchema.FFFF_07 FFFF               RIGHT OUTER JOIN mySchema.EEEE EEEE ON FFFF.9999 = EEEE.1B1B               RIGHT OUTER JOIN (                                 mySchema.DDDD DDDD                                 RIGHT OUTER JOIN mySchema.AAAA AAAA ON DDDD.1D1D = AAAA.1D1D                                 ) ON EEEE.PSPNR = AAAA.9999               LEFT OUTER JOIN mySchema.CCCC CCCC ON AAAA.3333 = CCCC.3333               LEFT OUTER JOIN mySchema.BBBB BBBB ON AAAA.3333 = BBBB.3333_INT               GROUP BY  AAAA.1D1D, AAAA.1111, AAAA.2222, BBBB.3333_EXT, CCCC.4444, DDDD.5555, DDDD.6666,                         DDDD.7777, DDDD.8888, AAAA.9999, EEEE.1010, EEEE.1A1A, EEEE.1B1B, FFFF.3333_LO,                         FFFF.1C1C         ON COMMIT DELETE ROWS);                         CREATE GLOBAL TEMPORARY TABLE myGGGG         AS             (SELECT  GGGG.1E1E, GGGG.1F1F, GGGG.1G1G, GGGG.1H1H, GGGG.1I1I, GGGG.1J1J,                     GGGG.1K1K, GGGG.R1D1D, GGGG.1L1L, GGGG.1M1M, GGGG.1N1N, GGGG.1O1O, GGGG.1P1P,                     GGGG.1Q1Q, HHHH.1R1R, IIII.1S1S, IIII.1T1T, IIII.1U1U, IIII.1V1V             FROM  mySchema.IIII IIII                   INNER JOIN mySchema.GGGG GGGG ON IIII.1K1K = GGGG.1K1K                   LEFT OUTER JOIN mySchema.HHHH HHHH ON GGGG.1L1L = HHHH.1W1W             WHERE ( GGGG.1M1M IN ('20', '30') )             AND   ( TO_DATE(IIII.1V1V, 'dd-mon-yyyy') = TO_DATE('31-DEC-9999','dd-mon-yyyy') )             AND ( TO_DATE(GGGG.1N1N, 'dd-mon-yyyy') >= TO_DATE('01-Jan-2011','dd-mon-yyyy') )         ON COMMIT DELETE ROWS);                 TRUNCATE TABLE FIDB;                 INSERT INTO FIDB (1111, 2222, 3333_EXT, 4444, 5555, 6666, 7777, 8888, 9999,                                   1010, 1A1A, 1B1B,3333_LO, 1C1C, 1D1D, 1E1E, 1F1F, 1G1G,                                   1H1H, 1I1I, 1J1J, 1K1K, R1D1D, 1L1L, 1M1M, 1N1N,                                   1O1O, 1P1P, 1Q1Q, 1R1R, 1S1S, 1T1T, 1U1U, 1V1V)            SELECT  myAAAA.1111, myAAAA.2222, myAAAA.3333_EXT, myAAAA.4444, myAAAA.5555, myAAAA.6666,                 myAAAA.7777, myAAAA.8888, myAAAA.9999, myAAAA.1010, myAAAA.1A1A, myAAAA.1B1B,                 myAAAA.3333_LO, myAAAA.1C1C, myAAAA.1D1D, myGGGG.1E1E, myGGGG.1F1F, myGGGG.1G1G,                 myGGGG.1H1H, myGGGG.1I1I, myGGGG.1J1J, myGGGG.1K1K, myGGGG.R1D1D,                 myGGGG.1L1L, myGGGG.1M1M, myGGGG.1N1N, myGGGG.1O1O, myGGGG.1P1P,                 myGGGG.1Q1Q, myGGGG.1R1R, myGGGG.1S1S, myGGGG.1T1T, myGGGG.1U1U, myGGGG.1V1V         FROM myGGGG INNER JOIN myAAAA ON myGGGG.R1D1D = myAAAA.1D1D         ORDER BY myGGGG.R1D1D;        COMMIT;     END;
    Thanks!

    Some people still sound mad at me because I have two queries and use temp tables
    Because in Oracle, unlike in sql server, you generally do not NEED temp tables at all.
    One of the biggest mistakes new Oracle developers make is to use PL/SQL when SQL will do the job just fine. Using PL/SQL when it isn't needed generally makes the code slower, less scalable and harder to maintain.
    One of the biggest mistakes sql server developers make when they use Oracle is to use temp table when they aren't needed. They try to write code in Oracle exactly the same way they wrote it in sql server. That creates temp tables that aren't needed, makes their code perform horribly and also makes it less scalable and harder to maintain.
    Oracle works differently and generally doesn't need ANY temp tables. You need to learn about how Oracle handles transactions and read consistency and how writers do NOT block readers and vice versa.
    Create a new thread and post FORMATTED code that shows the PROBLEM you are trying to solve and we can show you the proper way to solve it. That 'proper way' will likely NOT include any need for or use of temp tables.

  • How do I create a table within another table?

    How do I create a table within another table?
    As shown in image below (document created with Words), I already have a table with 3 columns. How do I create another table with 6 columns to tabulate the data (the one below "3.1 Overall")?

    Last time I checked in Pages 5.5.2 that is not possible.
    Peter

  • Create temp table in PL/SQL

    How to create temp table in PL/SQL procedure/function?
    In SQL plus, I can create a table using
    create table <table name>
    on commit reserve ..

    If you're referring to temp table similar as the temp table of informix .. the answer is you cannot create a temp table in oracle than will automatically be cleaned by oracle session.
    However its possible to create a remporary table but this will be a permanent part of your schema.. and you'll be the one responsible for dropping this table.
    regards,
    Victor ([email protected])
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Mike Chan:
    How to create temp table in PL/SQL procedure/function?
    In SQL plus, I can create a table using
    create table <table name>
    on commit reserve ..
    <HR></BLOCKQUOTE>
    null

  • Error in Creating Advance table within Advanvce Table via view link

    Hii all,
    i hve created a Advance table within Advanvce Table as given in the developer guide using the Detail functionality of the advance table
    im facing the following error................
    ## Detail 0 ##
    java.lang.NullPointerException
         at oracle.apps.fnd.framework.webui.OAAdvancedTableHelper.updateInnerTableProperties(OAAdvancedTableHelper.java:1752)
    i hve done all the steps as suggested by gurus to implement this Master Detail functionality. Pl help me out if any one had implemented it
    thanks in advanve
    Pranav

    Hi Reetesh,
    thanks for the reply...
    I hve already created a transient attribute in Master VO attached to the outter advance table and had set this attribute in detail attribute property of outter
    advance table. But im facing the same error.
    I u hve implemented this pl let me know the correct steps
    thanks
    Pranav

  • Creating a table from a query

    I am trying to create a table from the results of a query. With other products, I could issue the following SQL statement to achieve my goal but this doesn't work with Oracle.
    select MyTable.* into NewTable from MyTable where MAPID < 1000
    What am I missing?

    Try this way :
    create table NewTable as
    select * from MyTable where MAPID < 1000;

  • Create temp table using EXECUTE IMMEDIATE

    Is there any performance issue in creating globally temp table
    using EXECUTE IMMEDIATE or creating globally temp table from
    SQL PLUS.
    Any response will be greatly appreciated.
    null

    Anish,
    Creating tables is likely to be an expensive operation.
    Performance issues can only be considered in comparison to
    alternatives.
    Alternatives include: PLSQL tables, cursors and/or recoding so
    that tmp tables are not required. (One of our consultants reckons
    that sqlserver temp tables are usually used to get around
    limitations in sqlserver, ie slightly more complicated sql
    statements could be used instead of simpler sql and temporary
    tables).
    I would think creating the temp table once during sqlplus would
    be cheaper than creating and deleting it repeatedly at run time.
    Note that EXECUTE IMMEDIATE may do an implicit commit (dbms_sql
    certainly does). This may be got over my using the PRAGMA
    AUTONOMOUS_TRANSACTION; direction which places a
    procedure/function in a seperate transaction.
    Turloch
    P.S. We have some difficulty in getting information back from the
    field/customer sites. If you have questions and answers that are
    likely to be useful to other Oracle Migration Workbench
    users, and migrators in general, please send them in for possible
    inclusion in our Frequently Asked Question list.
    Oracle Migration Workbench Team
    Anish (guest) wrote:
    : Is there any performance issue in creating globally temp table
    : using EXECUTE IMMEDIATE or creating globally temp table from
    : SQL PLUS.
    : Any response will be greatly appreciated.
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Can i create temp tables in command?

    I need to create 5 temp tables and then use in CR for display. can this be done in Command?

    p.s. if this is regarding the same report that you've been dealing with for a couple of weeks now, please let us know exactly how you want the data to come back:
    a)  do you want 5 rows of data from 5 queries each returning one value, or
    b) do you want 1 row of data from queries with 5 columns
    e.g.
    a)
    field1
    1.6
    2.1
    3.1
    1.8
    2.6
    or
    b)
    field1     field2     field3     field4     field5
    1.6          2.1      3.1          1.8     2.6
    the a) or b) choice will determine what methods you can use to retrieve the data.
    if you don't want either a) or b) please describe how you want the data returned.
    -jamie

  • Creating a table within a PL/SQL procedure

    I recieve the following error:
    PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    The create statement is within the executable part of an if statement. Are we allowed to have CREATE statements within if statements?

    "Are we allowed to have CREATE statements within if statements? "
    Its nothing to do with IF, it applies throughout pl/sql to any DDL (data definition language).
    When the procedure is compiled, oracle checks that all of your DML (data definition language) complies with your database structure. If you mess about with the structure within the procedure, this confuses the whole issue. You can do it with native dynamic sql as suggested by Ino, but will need to use execute immediate wherever you attempt to use your new table, otherwise it will not compile.

  • Unable to create Temp table in Data mover

    Hi dudes,
    i tried to create a Temp table in Datamover but could not. i have tried to run it in user mode as well as bootstrap mode, even though not get success. i have added my sample datamover script, please go through the scripts and notice my error.
    SET LOG D:\PT851\log\test1537.log;
    SET NO DATA;
    SET NO TRACE;
    CREATE_TEMP_TABLE test1537DB;
    SET OUTPUT D:\PT851\test1537.out;
    EXPORT test1537DB;
    and my error is,
    Error Message:- PeopleTools 8.51 - Data Mover Copyright (c) 2012 PeopleSoft, Inc. All Rights Reserved Started: Sun Dec 23 02:57:24 2012 **** PeopleSoft trace has been turned off Data Mover Release: 8.51 Database: C91TST (ENG) Ended: Sun Dec 23 02:57:24 2012 **** PeopleSoft trace has been turned back on Unsuccessful completion

    Is the record definition test1537DB existing?

  • How to create a unique temp table then automatically remove after the join?

    i have many users simultaneously accessing the web apps.
    my problem is on how to solve the SELECT WHERE IN('..') clause..
    i've read a lot of threads that with the same option..
    1) open connection and start transaction
    2) create temp table
    3) insert the data (batch insert)
    4) do the main goal. SELECT JOIN or SELECT WHERE IN(SUBQUERY).
    5) end transaction and close connection
    how do I assure that the created temp table was remove/drop upon 5) ?
    thanks a lot..

    You can do this using global temporary tables. Also data from temporary table will be automatically deleted after commit but table will remain.
    e.g.
    CREATE GLOBAL TEMPORARY TABLE today_sales
    ON COMMIT DELETE ROWS
    AS SELECT * FROM orders WHERE order_date = SYSDATE;
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/tables.htm#i1006400
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2153132
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2153132
    Regards
    Rajesh
    Edited by: Rajesh on Jun 10, 2010 3:34 PM

  • Data storage in temp tables

    Question 1: I have created a global temporary table tt_groups(grp_ids number) on commit preserve rows; and I was wondering - if I have multiple users accessing this temp table at the same time, do I need to differenciate between the users, or will Oracle put a userid on them?
    Question 2: I am attempting to enter data into these temp tables within a function that will actually use the data. This function contains and returns a cursor. So far, I have been having great difficulties with this - to the point that I am ready to write an addition function just to store the data in the temp table. Does any one have any suggestions? Here is a sample of my code in case that would help. btw - str2tbl is a home grown conversion tool that parses a string and puts the data into rows of number. We have used it in many functions and so far don't have any issues associated with it.
    in_groupid IN VARCHAR2
    IS
    BEGIN
    INSERT INTO tt_groups(grp_ids)
    VALUES (
    SELECT Column_Value
    FROM THE (
    select cast(STR2TBL(in_groupid) as mytableType)
    from dual
    COMMIT;
    END;
    I am new to the whole sp/function coding, so any advice would be appreciated.
    Thanks,
    Susan

    Thanks, Justin, for your reply.
    I am pleased to hear that the temp table is session-specific.
    I attempted to update my statement to match what you suggested, but I am still getting "invalid" whenever I try to compile the function through schema mgr. Do you see anything that I might be missing? I incorporated the BEGIN; COMMIT; and END;, but is there something else that I am supposed to have? I downloaded a couple of Oracle handbooks and I have one book, Oracle8i - the complete reference, (we are using 9i) that I am referring to all the time, but I can't seem to get it to work! Here is more of my code:
    in_groupid IN VARCHAR2
    RETURN Types.ref_cursor
    AS
         resource_cursor types.ref_cursor;
    BEGIN
         OPEN resource_cursor FOR
    SELECT DISTINCT
    CATEGORY.CATID, SUBCATEGORY.SUBCATID
    FROM SUBCATEGORY, CATSUBCAT, CATEGORY, SUBRES
    WHERE SUBCATEGORY.SUBCATID = CATSUBCAT.SUBCATID AND
    CATSUBCAT.CATID = CATEGORY.CATID AND
    (CATSUBCAT.GROUPID IN (select grp_ids from tt_groups)) AND
    (SUBRES.GROUPID IN (select grp_ids from tt_groups))
    I want to insert this code into the function above:
    INSERT INTO dtra_tt_groups(grp_ids)
    SELECT Column_Value
    FROM THE (
    select cast(STR2TBL(in_groupid) as mytableType)
    from dual
    COMMIT;
    Where would I insert this statement?
    Thanks,
    Susan

  • How to Create a table in the middle of a transaction ?

    This software was written for sql and has a number of temporary table calls within transactions. We cannot precreate the temporary tables as some of the columns vary.
    So we create temp tables on the fly during the transaction, but the problem with that is that Oracle will commit your transaction at the point you create a temp table.
    Here's the logic:
    Begin Transaction
    Do some inserts, updates and deletes (IUDs)
    Create Global temp Table zx as select <some of those IUDs>
    Do some more inserts, updates and deletes
    Drop temp tables
    If worked
    Commit
    else
    Rollback entire transaction
    This is what I've tried so far:
    1. Run the create table on a different connection - has no visibility to the IUDs in the current transaction
    2. Split the create table and insert (instead of using CREATE AS) statements - to allow just the create table to be on a different connection - its going to be too much work to rewrite all the statements
    3. Create a permanent table instead of a temp table - same problem with committing data before the transaction has ended
    4. Put the Create As in a stored proc with AUTONOMOUS TRANSACTION turned on - same problem it has no visibility to the current outer transaction

    Thanks for coming on this thread
    The tables are used throughout the product, for example to
    (a) simplify complex queries, some too complex for oracle to process in one stmt
    (b) sub selects which will be reused
    (c) performance enhancements
    (d) left joins to summary queries
    We have 120 tables in our data model and there are many scenarios where temp tables are used. In sql server its not considered such a problem and programmers often create temp tables "on the fly".
    In fact, when we ported to oracle a couple of years ago, we had to add more temp table creates because some of the queries were too complex for oracle.
    It would be at least a months work to rewrite so temp tables are either not used or precreated, and we really have to go live with this build by the end of the week.
    No doubt we will rewrite these parts of the product to cut out temp tables, or perhaps drop oracle as a supported database, but for the time being we have oracle customers waiting for other fixes so I must find a way of giving them this software without doing this huge rewrite

  • Urgent!  Slow Result Set -- temp table slowing me??

    -- Running BC4J/JHeadstart/UIX
    Description:
    I have a uix page that calls a Servlet and passes a TABLE_NAME. The Servlet gets the TABLE_NAME and calls a class that extends oracle.jheadstart.persistence.bc4j.handler.DataSourceHandlerImpl to create a ViewObject and get the data we need. Once the ViewObject is passed back to the servlet, the servlet loops through the VIewObject and builds a report. See the problem below and the code at the bottom.
    Problem:
    I am running a query that returns approx 5000 records to my ViewObject. I then loop through the rows and construct a report. The view object will return the first 1085 records quickly, however, the following 4000 come back very slowly. I read online that BC4J creates temp tables to store large resultsets and then streams the data to the user as you need it. Is this our potential bottleneck?
    Questions:
    Is there a way to have it return all the rows? What can I do to speed this up?
    Code:
    --- Begin Servlet Snippet ---
    private ByteArrayOutputStream createReport(HttpServletRequest request)
    try{
    // PARM_REPORT = table name
    String reportName = request.getParameter(PARM_REPORT);
    System.out.println(">> calling getReport for " + reportName);
    RdmUserHandlerImpl handler = new RdmUserHandlerImpl();
    ViewObject vo = handler.getReportView2(reportName, request.getSession().getId());
    System.out.println(">> back from get report");
    // loop through report and print every 100
    while(vo.hasNext())
    curRow++;
    if (curRow % 100 == 0 )
    System.out.println(curRow + "");
    --- End Servlet Snippet ---
    --- Begin RdmUserHandlerImpl Snippet ---
    public ViewObject getReportView2(String tableName, Object sessionId) throws Exception {
    System.out.println("IN GET REPORT VIEW");
    ApplicationModule appMod = (ApplicationModule)getConnection("classpath...resource.MyUser", sessionId);
    // First see if we already created the view definition
    ViewObject vo = appMod.findViewObject(tableName);
    // If it was already created then refresh it, else lets try to create it
    if(vo != null) {
    System.out.println("found existing view");
    vo.reset();
    else {
    System.out.println("view not found, making new view");
    String query="SELECT * FROM " + tableName;
    System.out.println("QUERY = " + query);
    vo = appMod.createViewObjectFromQueryStmt(tableName, query);
    // max fetch returns -1
    System.out.println("MAX Fetch Size = " + vo.getMaxFetchSize());
    return vo;
    --- End RdmUserHandlerImpl Snippet ---
    Please reply asap! Deadline is coming fast!
    -Matt

    Matt,
    I think that you are right, the temporary tables created by BC4J are the reason for making it slow after a certain number of records. One of Steve Muench's articles includes the text:
    One of the most frequent performance-related questions we get on the Oracle Technet discussion forum is a question like, "After I query about a 1000 rows in a view object, my application gets very, very slow. What's happening?"
    It explains how you can turn off this feature, see the full article at http://www.oracle.com/technology/products/jdev/tips/muench/voperftips/index.html.
    The following article gives a lot of helpful information about the temporary tables:
    http://www.oracle.com/technology/products/jdev/htdocs/bc4j/bc4j_temp_tables.html
    The next article gives general tips for performance tuning of BC4J:
    http://www.oracle.com/technology/products/jdev/howtos/10g/adfbc_perf_and_tuning.html
    Hope this helps,
    Sandra Muller
    JHeadstart Team

Maybe you are looking for