CTE into temp table

I have query with many CTE:
;WITH CTE AS(...), CTE1 AS(....), CTE2 AS (...), CTE3 AS(...)
CTE4 AS(...), CTE5 AS(...), CTE6 AS(...), CTE7 AS(...), CTE8 AS(...), CTE9 AS(...), CTE10 AS(...), CTE11 AS(...)
SELECT * FROM CTE9 INNER JOIN CTE11 ON....
The last select works 3 minutes, but until CTE11 everything works in 1 second.
Is it possible to store CTE9 and CTE11 into temp table? (the same select form temp tables would execute immediately)
CTE9 and CTE11 has inside access to previous CTE's, so I can't break the query before CTE11 unless I create every CTE as temp table.

"I think it is too fragile."
If I store in physical table instead of temp table than if server go down, at least I will
have my data stored.
And it is not critical if this records are not available in main table for some time.
It could be solution, but requires some maintenance work in case server goes down or any other
uncatchable error .
But i guess I will just disable escalation.
My problem is quite simple. I have table "dbo.Stock" where is stock of products in warehouse. Lets say 1 million of products with some quantity. Each quantity of product has some ownership.
For example: i have quantity 1000 of product A. 500 quantity belongs to company1, 300 to company2 and 200 to company3.
Then at some time, I have to rearrange the ownership of lets say 200000 products(20%). (could be any number, more or less).
Until new ownership is not known, this stock should not be available for any operation - so, it is no problem, if this stock doesn't exists in table "dbo.Stock" at calculation time. But for other stock(800.000 products) all operations must be available.
So, i move(delete) this 200.000 products out of stock table and calculate ownership. This calculation
runs for 10 minutes. Then I move this stock back to the table(PK of most of the records is different now, so couldn't be update anyway).
Can you image that this table is locked for 10 minutes and it is very frequent one? Everything would stop for 10 minutes and i will get fired :)
What function? Do you have some description? I'm curious, maybe get some idea :)
Thanks,
Simon

Similar Messages

  • Insert into temp table with sorting not works

    Hi,
    Am inserting some of the values into temp table . Before going to insert i will be sorting a cloumn in descending order and then i will try insert. But actually inserts in ascending order.Dont know why.
    Please find the code
    Create table #TempTable( column1 smalldateTime )
    Insert into #TempTable
    Select distinct(column1) from table1 where cloumn2 = 1 order by  column1 desc
    When i query the table
    select * from  #TempTable
    shows the dates are in ascending order instead it should in descending
    But when i query this Select distinct(column1) from table1 where cloumn2 = 1 order by  column1 desc
    dates are in descending order which means recent dates fills top

    Or use a CTE = Common Table Expression:
    CREATE TABLE #test (id int);
    INSERT INTO #test
    SELECT object_id
    FROM sys.objects;
    SELECT COUNT(*)
    FROM #test;
    GO
    ;WITH cte AS
    (SELECT Top 2 *
    FROM #test
    ORDER BY id desc)
    DELETE FROM cte;
    GO
    SELECT COUNT(*)
    FROM #test;
    GO
    DROP TABLE #test;
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • SSIS package takes longer time when inserting data into temp tables

    querying records from one  server  and  inserting them into temp tables is taking longer time.
    are there any setting in package which  enhance the performance .

    will local temp table (#temp ) enhance the performance  ..
    If you're planning to use # tables in ssis make sure you read this
    http://consultingblogs.emc.com/jamiethomson/archive/2006/11/19/SSIS_3A00_-Using-temporary-tables.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • MS SQL Server 2014: Error inserting into Temp table with index and identity field

    In this thread, I mentioned a problem with SQL Server 2014:
    SQL Server 2014: Bug with IDENTITY INSERT ON
    The question was answered, it is a bug. To keep you informed on this issue, I open this discussion.
    Problem:
    The code below works perfectly fine on MS SQL Server 2008 R2 and MS SQL Server 2012, but gives an error every second time the proc is executed on MS SQL Server 2014. If I do not define any index on the temp table, the problem disappears. Defining the index
    after the insert, does not help.
    SET NOCOUNT ON
    GO
    IF EXISTS (SELECT 1 FROM sys.procedures WHERE name = 'usp_Test') DROP PROC dbo.usp_Test;
    GO
    CREATE PROC dbo.usp_Test AS
    BEGIN
    SET NOCOUNT ON
    CREATE TABLE #Source(ID integer NOT NULL);
    INSERT INTO #Source VALUES (1), (2), (3);
    CREATE TABLE #Dest (ID integer IDENTITY(1,1) NOT NULL);
    CREATE INDEX #IDX_Dest ON #Dest (ID);
    PRINT 'Check if the insert might cause an identity crisis';
    SELECT 'Source' AS SourceTable, * FROM #Source;
    SELECT 'Destination' AS DestTable, * FROM #Dest;
    SET IDENTITY_INSERT #Dest ON;
    PRINT 'Do the insert';
    INSERT INTO #Dest (ID) SELECT ID FROM #Source;
    PRINT 'Insert ready';
    SET IDENTITY_INSERT #Dest OFF;
    SELECT * FROM #Dest;
    DROP TABLE #Source;
    DROP TABLE #Dest;
    END;
    GO
    PRINT 'First execution of the proc, everything OK';
    EXEC dbo.usp_Test;
    PRINT '';
    PRINT 'Second execution of the proc, the insert fails.';
    PRINT 'Removing the index #IDX_Dest causes the error to disappear.';
    EXEC dbo.usp_Test;
    GO
    DROP PROC dbo.usp_Test;
    GO

    There is some progress. Communication from a former Microsoft employee tells us this:
    Shivendra Vishal
    Engineer at Microsoft
    I am no longer with MS, and I do not have code access, however from the public symbols, I could make out following:
    sqlmin!SetidentI2I4+0x1f3:
    000007fe`f4d865d3 488b10 mov rdx,qword ptr [rax] ds:00000000`00000000=????????????????
    ExceptionAddress: 000007fef4d865d3 (sqlmin!SetidentI2I4+0x00000000000001f3)
    ExceptionCode: c0000005 (Access violation)
    ExceptionFlags: 00000000
    NumberParameters: 2
    Parameter[0]: 0000000000000000
    Parameter[1]: 0000000000000000
    Attempt to read from address 0000000000000000
    This is a read AV and from registers it is clear that we were trying to move the value of location pointed by qword of register rax which is not valid:
    rax=0000000000000000 rbx=0000000000000038 rcx=0000000000001030
    rdx=0000000000000006 rsi=00000001f55def98 rdi=00000000106fd070
    rip=000007fef4d865d3 rsp=00000000106fcf40 rbp=00000000106fcfe9
    r8=0000000000000000 r9=00000001f55def60 r10=00000001f55defa0
    r11=00000000106fcd20 r12=0000000000000000 r13=0000000000000002
    r14=00000001f49c3860 r15=00000001f58c0040
    iopl=0 nv up ei pl nz na po nc
    cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010206
    The stack is:
    # Child-SP RetAddr Call Site
    00 00000000`106fcf40 000007fe`f30c1437 sqlmin!SetidentI2I4+0x1f3
    01 00000000`106fd050 000007fe`f474e7ce sqlTsEs!CEsExec::GeneralEval4+0xe7
    02 00000000`106fd120 000007fe`f470e6ef sqlmin!CQScanUpdateNew::GetRow+0x43d
    03 00000000`106fd1d0 000007fe`f08ff517 sqlmin!CQueryScan::GetRow+0x81
    04 00000000`106fd200 000007fe`f091cebe sqllang!CXStmtQuery::ErsqExecuteQuery+0x36d
    05 00000000`106fd390 000007fe`f091ccb9 sqllang!CXStmtDML::XretDMLExecute+0x2ee
    06 00000000`106fd480 000007fe`f08fa058 sqllang!CXStmtDML::XretExecute+0xad
    07 00000000`106fd4b0 000007fe`f08fb66b sqllang!CMsqlExecContext::ExecuteStmts<1,1>+0x427
    08 00000000`106fd5f0 000007fe`f08fac2e sqllang!CMsqlExecContext::FExecute+0xa33
    09 00000000`106fd7e0 000007fe`f152cfaa sqllang!CSQLSource::Execute+0x86c
    0a 00000000`106fd9b0 000007fe`f152c9e8 sqllang!CStmtExecProc::XretLocalExec+0x25a
    0b 00000000`106fda30 000007fe`f152a1d8 sqllang!CStmtExecProc::XretExecExecute+0x4e8
    0c 00000000`106fe1e0 000007fe`f08fa058 sqllang!CXStmtExecProc::XretExecute+0x38
    0d 00000000`106fe220 000007fe`f08fb66b sqllang!CMsqlExecContext::ExecuteStmts<1,1>+0x427
    0e 00000000`106fe360 000007fe`f08fac2e sqllang!CMsqlExecContext::FExecute+0xa33
    0f 00000000`106fe550 000007fe`f0902267 sqllang!CSQLSource::Execute+0x86c
    10 00000000`106fe720 000007fe`f0909087 sqllang!process_request+0xa57
    11 00000000`106feee0 000007fe`f2bf49d0 sqllang!process_commands+0x4a3
    12 00000000`106ff200 000007fe`f2bf47b4 sqldk!SOS_Task::Param::Execute+0x21e
    13 00000000`106ff800 000007fe`f2bf45b6 sqldk!SOS_Scheduler::RunTask+0xa8
    14 00000000`106ff870 000007fe`f2c136ff sqldk!SOS_Scheduler::ProcessTasks+0x279
    15 00000000`106ff8f0 000007fe`f2c138f0 sqldk!SchedulerManager::WorkerEntryPoint+0x24c
    16 00000000`106ff990 000007fe`f2c13246 sqldk!SystemThread::RunWorker+0x8f
    17 00000000`106ff9c0 000007fe`f2c13558 sqldk!SystemThreadDispatcher::ProcessWorker+0x3ab
    18 00000000`106ffa70 00000000`775d59ed sqldk!SchedulerManager::ThreadEntryPoint+0x226
    19 00000000`106ffb10 00000000`7780c541 kernel32!BaseThreadInitThunk+0xd
    1a 00000000`106ffb40 00000000`00000000 ntdll!RtlUserThreadStart+0x21
    Unassembling the function:
    000007fe`f4d8658e 4c8b10 mov r10,qword ptr [rax]
    000007fe`f4d86591 4533e4 xor r12d,r12d
    000007fe`f4d86594 410fb7d5 movzx edx,r13w
    000007fe`f4d86598 4533c9 xor r9d,r9d
    000007fe`f4d8659b 4533c0 xor r8d,r8d
    000007fe`f4d8659e 488bc8 mov rcx,rax
    000007fe`f4d865a1 4489642420 mov dword ptr [rsp+20h],r12d
    000007fe`f4d865a6 41ff5230 call qword ptr [r10+30h]
    000007fe`f4d865aa 8b5597 mov edx,dword ptr [rbp-69h]
    000007fe`f4d865ad 4c8b10 mov r10,qword ptr [rax]
    000007fe`f4d865b0 4489642438 mov dword ptr [rsp+38h],r12d
    000007fe`f4d865b5 4489642430 mov dword ptr [rsp+30h],r12d
    000007fe`f4d865ba 458d442401 lea r8d,[r12+1]
    000007fe`f4d865bf 4533c9 xor r9d,r9d
    000007fe`f4d865c2 488bc8 mov rcx,rax
    000007fe`f4d865c5 c644242801 mov byte ptr [rsp+28h],1
    000007fe`f4d865ca 4488642420 mov byte ptr [rsp+20h],r12b
    000007fe`f4d865cf 41ff5250 call qword ptr [r10+50h]
    000007fe`f4d865d3 488b10 mov rdx,qword ptr [rax] <=================== AV happened over here
    000007fe`f4d865d6 488bc8 mov rcx,rax
    000007fe`f4d865d9 4c8bf0 mov r14,rax
    000007fe`f4d865dc ff5268 call qword ptr [rdx+68h]
    000007fe`f4d865df 488d55e7 lea rdx,[rbp-19h]
    000007fe`f4d865e3 4c8b00 mov r8,qword ptr [rax]
    000007fe`f4d865e6 488bc8 mov rcx,rax
    000007fe`f4d865e9 41ff5010 call qword ptr [r8+10h]
    000007fe`f4d865ed f6450a04 test byte ptr [rbp+0Ah],4
    I remember few issues with scan2ident function, I am not sure if they have fixed it however it appears that this is intoduced to SQL 2014 and we need help from MS to get this resolved as it needs code analysis.
    It is not getting simulated for other versions of SQL apart from SQL 2014.
    Also to add, interestingly, the value of rax is not visibly changed and it was successfully passed on to rcx, which has a valid value, so something should have changed the value of rax inside call to function using call qword ptr [r10+50h], and looking at this
    it appears that it might be a list of functions and we are going at particular offset [50h]. So, bottom line is that the call to function qword ptr [r10+50h], should be changing something in rax, and debugging/analyzing this code might give us some more idea.

  • Please help - Can not use stored procedure with CTE and temp table in OLEDB source

    Hi,
       I am going to create a simple package. It has OLEDB source , a Derived transformation and a OLEDB Target database.
    Now, for the OLEDB Source, I have a stored procedure with CTE and there are many temp tables inside it. When I give like EXEC <Procedure name> then I am getting the error like ''The metadata  could not be determined because statement with CTE.......uses
    temp table. 
    Please help me how to resolve this ?

    you write to the temp tables that get created at the time the procedure runs I guess
    Instead do it a staged approach, run Execute SQL to populate them, then pull the data using the source.
    You must set retainsameconnection to TRUE to be able to use the temp tables
    Arthur My Blog

  • Remove all duplicate records and load into temp table

    Hi
    I have a table contains data like this.
    Emp No Designation location
    1111 SE CA
    1111 DE CT
    3456 WE NJ
    4523 TY GH
    We found that there are two duplicate records for emp no: 1111. I want to delete all duplicate records (in this case two records for emp no:1111) and load into the temp table.
    Please advice me how to do it.

    Oh look, you can search the forums...
    http://forums.oracle.com/forums/search.jspa?threadID=&q=delete+duplicates&objID=f75&dateRange=all&userID=&numResults=30

  • Select into Temp Table Identity Column

    I'm trying to select data into a temp table but how would I select the identity column into my temp table. This is what I have so far(RefId is the identity Column (1,1)
    BEGIN TRAN
    SELECT [RefId]
    ,[Name]
    ,[CreationDate]
    ,[CreatedBy]
    ,[ModificationDate]
    ,[ModifiedBy]
    ,[RegistrationNumber]
    ,[EmployerType]
    ,[EmployerState]
    ,[ProviderLegalDescription]
    ,[WeeklySalaryDateType]
    ,[WeeklySalaryDateDay]
    ,[FortnightlySalaryDateType]
    ,[FortnightlySalaryDateDay]
    ,[MonthlySalaryDateType]
    ,[MonthlySalaryDateDay]
    ,[TrustLevel]
    ,[ForceDeductionOverrides]
    ,[PayrollPaypointlDeductionsEnabled]
    ,[PaypointRefId]
    ,[PayrollBackupEnabled]
    ,[PayrollBackupFailedPaymentsBefore]
    ,[PayrollBackupType]
    ,[PayrollBackupUploadType]
    ,[PayrollBackupEnableAutomation]
    ,[PayrollBackupAutomationType]
    ,[PayrollBackupFtpServer]
    ,[PayrollBackupFtpPort]
    ,[PayrollBackupFtpPassword]
    ,[PayrollBackupEmail]
    ,[PayrollBackupFtpUsername]
    ,[EnforceSingleProduct]
    ,[AffordabilityOverride]
    ,[AffordabilityReoccuringIncomePercent]
    ,[AffordabilityAdHocIncomePercent]
    ,[AffordabilityVariableIncomePercent]
    ,[AffordabilityNumerator]
    ,[AffordabilityExposure]
    ,[ExternalIdentificationNumber]
    ,[DeductionType]
    ,[IsValidated]
    ,[ValidatedBy]
    ,[ValidatedDate] INTO #TempEmployers FROM Employers WHERE RefId=2
    SELECT
    Name, COUNT(*) AS Repeats INTO #Temp
    FROM
    Employers
    GROUP BY
    Name
    HAVING
    COUNT(*) > 1
    Declare @Nam nvarchar(250)
    While (Select Count(*) From #Temp) > 0
    Begin
    Select Top 1 @Nam = Name From #Temp
    --Do some processing here
    Delete #Temp Where @Nam = Name
    INSERT INTO #TempEmployers
    SELECT [RefId]
    ,[Name]
    ,[CreationDate]
    ,[CreatedBy]
    ,[ModificationDate]
    ,[ModifiedBy]
    ,[RegistrationNumber]
    ,[EmployerType]
    ,[EmployerState]
    ,[ProviderLegalDescription]
    ,[WeeklySalaryDateType]
    ,[WeeklySalaryDateDay]
    ,[FortnightlySalaryDateType]
    ,[FortnightlySalaryDateDay]
    ,[MonthlySalaryDateType]
    ,[MonthlySalaryDateDay]
    ,[TrustLevel]
    ,[ForceDeductionOverrides]
    ,[PayrollPaypointlDeductionsEnabled]
    ,[PaypointRefId]
    ,[PayrollBackupEnabled]
    ,[PayrollBackupFailedPaymentsBefore]
    ,[PayrollBackupType]
    ,[PayrollBackupUploadType]
    ,[PayrollBackupEnableAutomation]
    ,[PayrollBackupAutomationType]
    ,[PayrollBackupFtpServer]
    ,[PayrollBackupFtpPort]
    ,[PayrollBackupFtpPassword]
    ,[PayrollBackupEmail]
    ,[PayrollBackupFtpUsername]
    ,[EnforceSingleProduct]
    ,[AffordabilityOverride]
    ,[AffordabilityReoccuringIncomePercent]
    ,[AffordabilityAdHocIncomePercent]
    ,[AffordabilityVariableIncomePercent]
    ,[AffordabilityNumerator]
    ,[AffordabilityExposure]
    ,[ExternalIdentificationNumber]
    ,[DeductionType]
    ,[IsValidated]
    ,[ValidatedBy]
    ,[ValidatedDate] FROM Employers
    WHERE Name= @Nam
    End
    SELECT * FROM #TempEmployers
    ROLLBACK

    Hi,
    Its the RefId column, I just need the actual values. Im getting the following error:
    Column name or number of supplied values does not match table definition. And it points to The RefId
    Column
    If your question is regarding passing explicit values for identity column you need to set IDENTITY_INSERT to ON and pass a columnlist for the table
    Which column in this is IDENTITY?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to insert text data into temp tables....

    Dear All,
    I have one notepad with three columns, first column is segment1, second column is segment2 & third column is price list....
    and there is no delimiter and exact spaces..(i.e, zizak fomat)
    Ex:-
    xx yy 00009999
    kk mmmm 00009333
    Data is available like above example...So, I need to insert this data into one table.(2LAKSHS OF RECORDS AVAILABLE IN THAT NOTEPAD)
    So, Any can one help me, how to insert this kind of text data into temparory table...
    Regards
    Krishna
    Edited by: user12070109 on May 29, 2010 9:48 PM
    Edited by: user12070109 on May 29, 2010 9:49 PM

    Hello,
    What manu suggested this can be done through oracle forms.
    If as i read your last post you are using that in database it will not work in db. Try to use the same process in oracle forms will work by making some changes.
    And if you don't want to use forms then there is one way using SQL LOADER. It required control file to execute for uploading data.
    See the below link.
    http://www.orafaq.com/wiki/SQL*Loader_FAQ
    In this example its showing filename.csv you can use your file name like yourfilename.txt.
    So your control file will look like this...
    load data
    infile 'file_path\file_name.txt'
    into table table_name  -- use actual table name where you want to upload data
    fields terminated by " "  -- Here using spaces as you mentioned           
    (column1, column2, column3)  -- Here use the three column names of tableAnd after creating control file with the above code. You can call it in command prompt like this
    sqlldr username/password control=control_file_path\control_file_name.ctl log=log_file_path\log_file_name.log
    or
    sqlldr username/password@dbconnection control=control_file_path\control_file_name.ctl log=log_file_path\log_file_name.log
    Before doing this practice make sure SQLLDR.exe availabe in the machine where you have to execute. Otherwise you will have to install db client for using sqlldr.exe
    -Ammad

  • How do i insert into temp table

    Hi ALL,
    I have a table APP
    APP_I Acronym Desc
    1 ACC Accounts
    PLTFRM
    swr_pltfrm_i swr_pltfrm_x swr_pltfrm_typ_x
    1 AIX-JAVA Execution
    2 COBOL/BATCH Execution
    3 COBOL/CICS Execution
    4 CONSULTWORKS/MOBILE Delivery
    5 CONSULTWORKS Delivery
    PLTFRM_APP_ENVT
    swr_pltfrm_i app_i
    1 1
    2 1
    3 1
    4 1
    5 1
    I want to create one temporary tab
    TEMP_insert(app_i,desc, acrnymc ,delivery,execution) which have this columns
    App_i desc acrnymc execution
    1 Accounts ACC AIX-JAVA,COBOL/BATCH,COBOL/CICS
    delivery
    CONSULTWORKS,CONSULTWORKS/MOBILE
    How do i insert the row in to the Temp_Insert table based on APP_I as input to my stored procedure.
    Thanks

    hopefully this will help
    dev>declare
      2      cursor c is select empno,ename,job from emp where deptno=20 and rownum<3;
      3      str varchar2(100);
      4  begin
      5      for cur in c loop
      6          str:=str||' '||cur.ename||' '||cur.job;
      7      end loop;
      8      insert into emp_test (ename) VALUES(str);
      9  end; 
    10  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    dev>select ename from emp_test;
    ENAME
    SMITH CLERK JONES MANAGER
    [pre                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Difference betweem temp table and CTE as performance wise?

    Hi Techies,
    Can anyone explain CTE and Temp table performance wise. Which is the better object to use while implementing DML operations.
    Thanks in advance.
    Regards
    Cham bee

    Welcome to the world of performance tuning in SQL Server! The standard answer to this kind of question is:
    It depends.
    A CTE is a logical construct, which specifies the logical computation order for the query. The optimizer is free to recast computation order in such away that the intermediate result from the CTE never exists during the calculation. Take for instance this
    query:
    WITH aggr AS (
        SELECT account_no, SUM(amt) AS amt
        FROM   transactions
        GROUP  BY account_no
    SELECT account_no, amt
    FROM   aggr
    WHERE  account_no BETWEEN 199 AND 399
    Transactions is a big table, but there is an index on account_no. In this example, the optimizer will use that index and only compute the total amount for the accounts in the range. If you were to make a temp table of the CTE, SQL Server would have no choice
    to scan the entire table.
    But there also situations when it is better to use a temp table. This is often a good strategy when the CTE appears multiple times in the query. The optimizer is not able to pick a plan where the CTE is computed once, so it may compute the CTE multiple times.
    (To muddle the waters further, the optimizers in some competing products have this capability.)
    Even if the CTE is only referred to once, it may help to materialise the CTE. The temp table has statistics, and those statistics may help the optimizer to compute a better plan for the rest of the query.
    For the case you have at hand, it's a little difficult to tell, because it is not clear to me if the conditions are the same for points 1, 2 and 3 or if they are different. But the second one, removing duplicates, can be quite difficult with a temp table,
    but is fairly simple using a CTE with row_number().
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How can I get rid of Global Temp Table

    Hello,
    I've been writing PL/SQL stored proc for creating reports on VB.NET front end. Until now, I've been using session specific global temp table to store intermediate results and at the end I pass the result set to .NET via reference cursor. The reports are created by simply binding the ref cursor result sets to .NET grids. It's been working fine, but I am kind of bothered by the temp tables. I looked on other options, but couldn't really come up with one.
    Can somebody suggest me how I can get rid of those temp tables? Thanks,

    Tubby, that's exactly I was trying to do. I think that table type has to be defined in database, not within PL/SQL. How can I create that table of user defined record type? I tried that, but it doesn't allow me. I think I am missing something. For example,
    create type group_t is record
    (A varchar2,
    B number,
    C number)
    now inside sp, i have something like:
    type my_group is table of group_t index by binary_integer
    now I have sp cursor as
    cursor cur_test IS 'ABC' as A, 1 as B, 5 as C
    now i do something like this. My original queries are longer and much more complicated so please don't suggest you can directly open ref cursor for this query.
    FETCH cur_test BULK COLLECT INTO my_group;
    Then I do all the processing, calculations, totals, sub-totals, and insert into temp table and return via ref cursor.
    My problem is I can't directly fetch into the above table you mentioned. How should I go about in this situation?
    Maybe I should STOP thinking about this approach and just do whatever I've been doing or solve it through pure SQL. However, there are tons of problems with pure SQL approach.

  • How i can disable MONITORING temp tables

    In the Oracle 10 g database stats are gathering using
    Gtaher_stats_job
    current setting is statictics _level =Typical
    i need to disable the monotoring for temp tables
    i try this command it will not change
    ALTER TABLE "RDC"."INV_TEMP"
    NOMONITORING
    How i can disable this , i read some artikel this feature is disabled in oracle 10g
    how i can disable
    tks
    rda

    Justin Note
    I would suggest that this is probably a bad idea, though. If there are no statistics on an object,
    you're basically asking the CBO to work blind. Why not gather statistics after loading a fresh set of data
    into the table?
    I am running stats once a week , so i cannnot gather fresh set of dataNicolas
    setting stats to a given value and lock them (to be not set to 0 by any gather stat process) may help as well.
    Justin
    Nicolas.
    I cannot understand this >>to be not set to 0 by any gather stat processOk my process as follows
    through sqlldr i load a data to temp table , i have a after insert trigger
    once the data insert into temp table it check for some condition and
    fire this trigger and insert into Permanent Table,
    After the process finished the temp table truncated.
    this whole process running every day .
    I already mention stats are collected once a week , no point i keep the stats
    for this temp table and suppose if i keep , it will give wong execution plan
    and insert into this temp tabel will be slow -- am i right in this step
    This is the reason i dont want stats at all in temp table
    Thanks Justin & Nicolas
    Best rds

  • Insert into some sort of temp table?

    Hi there,
    Not sure how to do this, I have three Two CTEs
    with a as (select field1, field2, field3 from table1),
    b as (select field1, field2, field3 from table2)
    Now I would like to insert each result from the above CTE into some kind of table or something. I would not want to use a temp table cause I read that's not a good approach. I'm kind of new to the Oracle world. I'm coming from a SQL server background and the way I would do it in SQL server would something like creating a Table variable and inserting all the result sets into that table variable, hence avoiding the creation of a temp table with in Oracle its more like a permanent table I read.
    Let me know what would be the best approach to accomplish this task here.
    Thanks very much for your help.

    Hi,
    Sorry, I don't understand what you want.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using.
    Midway wrote:
    Hi there,
    Not sure how to do this, I have three Two CTEs
    with a as (select field1, field2, field3 from table1),
    b as (select field1, field2, field3 from table2)Why do you need CTEs? Why can't you just use table1 and table2?
    Now I would like to insert each result from the above CTE into some kind of table or something. I would not want to use a temp table cause I read that's not a good approach. I'm kind of new to the Oracle world. I'm coming from a SQL server background and the way I would do it in SQL server would something like creating a Table variable and inserting all the result sets into that table variable, hence avoiding the creation of a temp table with in Oracle its more like a permanent table I read.
    Let me know what would be the best approach to accomplish this task here.What is the task that you want to accomplish?
    Is INSERTing really the goal, or is that a means you might use to accomplish your real task?
    If all you want to do is generate a specific output, then I'm sure you don't need any other tables, temporary or otherwise. Exactly how to do it depends on what data is in your actual tables, and what results you want from that data. As long as I don't know where you're starting from, or where you want to go, I can't give you very good directions.

  • How to read the data file and write into the same file without a temp table

    Hi,
    I have a requirement as below:
    We are running lockbox process for several business, but for a few businesses we have requirement where in we receive a flat file in different format other than how the transmission format is defined.
    This is a 10.7 to 11.10 migration. In 10.7 the users are using a custom table into which they are first loading the raw data and writing a pl/sql validation on that and loading it into a new flat file and then running the lockbox process.
    But in 11.10 we want to restrict using temp table how can we achieve this.
    Can we read the file first and then do validations accordingly and then write to the same file and process the lockbox.
    Any inputs are highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

    Hello Gurus,
    Let me tell you about my requirement clearly with an example.
    Problem:
    i am receiving a dat file from bank in below format
    105A371273020563007 07030415509174REF3178503 001367423860020015E129045
    in this detail 1 record starting from 38th character to next 15 characters is merchant reference number
    REF3178503 --- REF denotes it as Sales Order
    ACC denotes it as Customer No
    INV denotes it as Transaction Number
    based on this 15 characters......my validation comes.
    If i see REF i need to pick that complete record and then fill that record with the SO details as per my system and then submit the file for lockbox processing.
    In 10.7 they created a temporary table into which they are loading the data using a control file....once the data is loaded into the temporary table then they are doing a validation and updating the record exactly as required and then creating one another file and then submitting the file for lockbox processing.
    Where as in 11.10 they want to bypass these temporary tables and writing it into a different file.
    Can this be handled by writing a pl/sql procedure ??
    My findings:
    May be i am wrong.......but i think .......if we first get the data into ar_payments_interface_all table and then do the validations and then complete the lockbox process may help.
    Any suggestions from Oracle GURUS is highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

  • Does a temp table is reuired to insert into a table

    Hi ,
    I am using a stored procedure to check the availability of a record in a table and deleting the record if exists ,
    actually  if the user have multiple record i need to delete and store it in removed table  , so i used insert with select command to insert into the table , do i need to use a temp table to insert multiple record in removed table .
    Thank You
    Jeevan Vinay

    No, it doesn't need to be that complex.
    The records need to go to your deleted/history table, and they also need to be deleted from the main table. I would just insert the records into the history table and delete the records from your main table by joining back to it on the delete with the PK.
    You could try something like this:
    CREATE TABLE ##main_table (employee_id INT IDENTITY(1,1), employee_name VARCHAR(50))
    CREATE TABLE ##history_table (employee_id INT, employee_name VARCHAR(50))
    INSERT INTO ##main_table (employee_name)
    SELECT 'Alice'
    UNION ALL
    SELECT 'Bob'
    UNION ALL
    SELECT 'Charlie'
    --Bob is the user that will get deleted (employee_id = 2)
    --Insert record into history table
    INSERT INTO ##history_table
    SELECT *
    FROM ##main_table
    WHERE employee_id = 2
    --Delete record from main table
    DELETE m
    FROM ##main_table m
    JOIN ##history_table h
    ON m.employee_id = h.employee_id
    SELECT *
    FROM ##history_table
    SELECT *
    FROM ##main_table

Maybe you are looking for