bulk-collect

SQL Server Equivalent of Bulk Collect in Oracle

时光总嘲笑我的痴心妄想 提交于 2020-01-07 04:44:24
问题 I want to replicate the following code in SQL Server. I've had a look around and it seems like the only option is to just use a straight cursor, but is there a better way: DECLARE CURSOR cursor1 IS SELECT * FROM table1; TYPE cursor_aat IS TABLE OF cursor1%ROWTYPE; l_cursor cursor_aat; BEGIN OPEN cursor1; LOOP FETCH cursor1 BULK COLLECT INTO l_cursor LIMIT 200; FOR INDX IN 1 .. l_cursor.COUNT LOOP IF (CheckSomeData() = 0) THEN INSERT INTO new_table (col1, col2) values (l_cursor(INDX).col1, l

Insert bulk records in to remote database (dblink) using Bulk Collect

大兔子大兔子 提交于 2020-01-04 07:42:07
问题 I want to insert huge records from different tables in to a destination remote table 'Audition_Detail' using DBLINK - @FMATLINK. I have used Bulk collect, but its throwing errors. I have gone through some links too: Overcoming the restriction on bulk inserts over a database link PLS-00394: Wrong number of values in the INTO list of a fetch statement The code is as follows: DECLARE TYPE FETCH_ARRAY IS TABLE OF AUDITION_DETAIL@FMATLINK%ROWTYPE; A_DATA FETCH_ARRAY; CURSOR A_CUR IS --------------

How do I select from Bulk Collected Table of Records Type

ⅰ亾dé卋堺 提交于 2020-01-02 04:04:14
问题 I've got a procedure where I need to cache some data, for performance reasons, for downstream operations. The TYPE definitions work The BULK COLLECT INTO works The SELECT does not work PROCEDURE MYPROC((PARAMS))AS TYPE REC_TYPE IS RECORD ( COLUMN_1 (TABLEA.COLUMN_A)%TYPE, COLUMN_2 (TABLEA.COLUMN_B)%TYPE ); TYPE TAB_TYPE IS TABLE OF REC_TYPE; TABLE_1 TAB_TYPE; BEGIN SELECT COLUMN_A, COLUMN_B BULK COLLECT INTO TABLE_1 FROM TABLE_A; SELECT * FROM TABLE_1; END MYPROC; Yields: Error(#,#): PL/SQL:

How to do conditional processing in a bulk collect loop?

爱⌒轻易说出口 提交于 2019-12-23 04:02:40
问题 we have Oracle 11G and i'm trying to move data from one table to another using bulk collect . Problem is when I tried to evaluate if one field from origin is empty my package got invalidated. What I have: Declaration: CREATE OR REPLACE PACKAGE MYSCHEMA.MYPKG AS CURSOR CUR_MYDATA IS SELECT o.name, o.last_name, o.id, o.socnum FROM origin o WHERE 1=1 AND o.name like upper ('a%'); TYPE t_name IS TABLE OF origin.name%TYPE; TYPE t_lastname IS TABLE OF origin.last_name%TYPE; TYPE t_id IS TABLE OF

Return data rows from a pl/sql block

荒凉一梦 提交于 2019-12-14 03:15:01
问题 I want to write pl/sql code which utilizes a Cursor and Bulk Collect to retrieve my data. My database has rows in the order of millions, and sometimes I have to query it to fetch nearly all records on client's request. I do the querying and subsequent processing in batches, so as to not congest the server and show incremental progress to the client. I have seen that digging down for later batches takes considerably more time, which is why I am trying to do it by way of cursor. Here is what

Use Bulk Collect result in a select query without cursor

一个人想着一个人 提交于 2019-12-08 11:47:57
问题 I am new to PL/SQL and I was wondering if I can use result of a bulk collect like this: Declare type result_bulk_type is Table of table1.ID%type; result_bulk result_bulk_type; BEGIN SELECT id BULK COLLECT INTO result_bulk FROM table1; UPDATE table2 SET status=1 WHERE id IN result_bulk; END; I got errors at compilation: PL/SQL: SQL statement ignored PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got SYS_PLSQL_22223_23_1 Thanks for your help! 回答1: No, it can't be done in this way.

How do I select from Bulk Collected Table of Records Type

浪尽此生 提交于 2019-12-05 07:24:38
I've got a procedure where I need to cache some data, for performance reasons, for downstream operations. The TYPE definitions work The BULK COLLECT INTO works The SELECT does not work PROCEDURE MYPROC((PARAMS))AS TYPE REC_TYPE IS RECORD ( COLUMN_1 (TABLEA.COLUMN_A)%TYPE, COLUMN_2 (TABLEA.COLUMN_B)%TYPE ); TYPE TAB_TYPE IS TABLE OF REC_TYPE; TABLE_1 TAB_TYPE; BEGIN SELECT COLUMN_A, COLUMN_B BULK COLLECT INTO TABLE_1 FROM TABLE_A; SELECT * FROM TABLE_1; END MYPROC; Yields: Error(#,#): PL/SQL: ORA-00942: table or view does not exist I've also tried wrapping it in a table function like I do with

bulk collect using “for update”

旧街凉风 提交于 2019-11-30 23:25:30
I run into an interesting and unexpected issue when processing records in Oracle (11g) using BULK COLLECT. The following code was running great, processing through all million plus records with out an issue: -- Define cursor cursor My_Data_Cur Is Select col1 ,col2 from My_Table_1; … -- Open the cursor open My_Data_Cur; -- Loop through all the records in the cursor loop -- Read the first group of records fetch My_Data_Cur bulk collect into My_Data_Rec limit 100; -- Exit when there are no more records to process Exit when My_Data_Rec.count = 0; -- Loop through the records in the group for idx in

bulk collect using “for update”

我怕爱的太早我们不能终老 提交于 2019-11-30 18:05:59
问题 I run into an interesting and unexpected issue when processing records in Oracle (11g) using BULK COLLECT. The following code was running great, processing through all million plus records with out an issue: -- Define cursor cursor My_Data_Cur Is Select col1 ,col2 from My_Table_1; … -- Open the cursor open My_Data_Cur; -- Loop through all the records in the cursor loop -- Read the first group of records fetch My_Data_Cur bulk collect into My_Data_Rec limit 100; -- Exit when there are no more