Help in BULK COLLECT
In emp table having 14 records when i use the BULK COLLECT its inserting the 12 records only
with out limting its working fine But when u limit the records inserting the 12 records only
i need 14 records to be inserted in emps table through limiting ..
Suggest me in this
DECLARE
TYPE a_recs IS TABLE OF emps%ROWTYPE;
v_recs a_recs;
CURSOR c1 IS
SELECT *
FROM emp;
BEGIN
DELETE FROM emps;
COMMIT;
OPEN c1;
LOOP
FETCH c1 BULK COLLECT INTO v_recs LIMIT 3;
EXIT WHEN c1%NOTFOUND;
FORALL i IN v_recs.FIRST..v_recs.LAST
INSERT INTO emps
VALUES v_recs(i);
END LOOP;
CLOSE c1;
END;Thanks
assuming this is only an exercise, change the order of FORALL and EXIT
FORALL i IN v_recs.FIRST..v_recs.LAST
INSERT INTO emps
VALUES v_recs(i);
EXIT WHEN c1%NOTFOUND;otherwise, just do
insert into emps
select *
from empEdited by: Alex Nuijten on Aug 5, 2009 8:50 AM
Similar Messages
-
Need help with Bulk Collect ForAll Update
Hi - I'm trying to do a Bulk Collect/ForAll Update but am having issues.
My declarations look like this:
CURSOR cur_hhlds_for_update is
SELECT hsh.household_id, hsh.special_handling_type_id
FROM compas.household_special_handling hsh
, scr_id_lookup s
WHERE hsh.household_id = s.id
AND s.scr = v_scr
AND s.run_date = TRUNC (SYSDATE)
AND effective_date IS NULL
AND special_handling_type_id = 1
AND created_by != v_user;
TYPE rec_hhlds_for_update IS RECORD (
household_id HOUSEHOLD_SPECIAL_HANDLING.household_id%type,
spec_handl_type_id HOUSEHOLD_SPECIAL_HANDLING.SPECIAL_HANDLING_TYPE_ID%type
TYPE spec_handling_update_array IS TABLE OF rec_hhlds_for_update;
l_spec_handling_update_array spec_handling_update_array;And then the Bulk Collect/ForAll looks like this:
OPEN cur_hhlds_for_update;
LOOP
FETCH cur_hhlds_for_update BULK COLLECT INTO l_spec_handling_update_array LIMIT 1000;
EXIT WHEN l_spec_handling_update_array.count = 0;
FORALL i IN 1..l_spec_handling_update_array.COUNT
UPDATE compas.household_special_handling
SET effective_date = TRUNC(SYSDATE)
, last_modified_by = v_user
, last_modified_date = SYSDATE
WHERE household_id = l_spec_handling_update_array(i).household_id
AND special_handling_type_id = l_spec_handling_update_array(i).spec_handl_type_id;
l_special_handling_update_cnt := l_special_handling_update_cnt + SQL%ROWCOUNT;
END LOOP;And this is the error I'm receiving:
ORA-06550: line 262, column 31:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 262, column 31:
PLS-00382: expression is of wrong type
ORA-06550: line 263, column 43:
PL/SQL: ORA-22806: not an object or REF
ORA-06550: line 258, column 9:
PL/SQL: SQMy problem is that the table being updated has a composite primary key so I have two conditions in my where clause. This the the first time I'm even attempting the Bulk Collect/ForAll Update and it seems like it would be straight forward if I was only dealing with a single-column primary key. Can anyone please help advise me as to what I'm missing here or how I can accomplish this?
Thanks!
ChristineYou cannot reference a column inside a record when doin a for all. You need to refer as a whole collection . So you will need two collections.
Try like this,
DECLARE
CURSOR cur_hhlds_for_update
IS
SELECT hsh.household_id, hsh.special_handling_type_id
FROM compas.household_special_handling hsh, scr_id_lookup s
WHERE hsh.household_id = s.ID
AND s.scr = v_scr
AND s.run_date = TRUNC (SYSDATE)
AND effective_date IS NULL
AND special_handling_type_id = 1
AND created_by != v_user;
TYPE arr_household_id IS TABLE OF HOUSEHOLD_SPECIAL_HANDLING.household_id%TYPE
INDEX BY BINARY_INTEGER;
TYPE arr_spec_handl_type_id IS TABLE OF HOUSEHOLD_SPECIAL_HANDLING.SPECIAL_HANDLING_TYPE_ID%TYPE
INDEX BY BINARY_INTEGER;
l_household_id_col arr_household_id;
l_spec_handl_type_id_col arr_spec_handl_type_id;
BEGIN
OPEN cur_hhlds_for_update;
LOOP
FETCH cur_hhlds_for_update
BULK COLLECT INTO l_household_id_col, l_spec_handl_type_id_col
LIMIT 1000;
EXIT WHEN cur_hhlds_for_update%NOTFOUND;
FORALL i IN l_household_id_col.FIRST .. l_household_id_col.LAST
UPDATE compas.household_special_handling
SET effective_date = TRUNC (SYSDATE),
last_modified_by = v_user,
last_modified_date = SYSDATE
WHERE household_id = l_household_id_col(i)
AND special_handling_type_id = l_spec_handl_type_id_col(i);
--l_special_handling_update_cnt := l_special_handling_update_cnt + SQL%ROWCOUNT; -- Not sure what this does.
END LOOP;
END;G. -
Hi All,
I need a help to create a bulk statement. Please find the scenario below
I would like to copy a table A from table B using bulk collect also the table A has more records (1Million). Before doing this I need to either truncate the table B or drop the table to load the data from table A.
Please provide me the correct statement to achieve this request. Thanks in advance!!
Regards,
Boovan.disabling any indexes on the target should be looked at first. If there are none then look at the above.
When you do a direct path load the indexes are build after loading.The point is that the direct path load does not avoid the undo due to the indexes.
In this example on a table with no indexes the undo used goes from 216kb to 16kb using append.
When an index is added the undo used goes up from 216kb to 704kb an increase of 488kb for a standard insert.
For the direct path insert the undo goes up from 16kb to 440kb so almost the full amount of undo due to the index.
So the presence of a single index can have a much greater impact on the amount of undo required than the use of a direct path load and that undo may not be avoided by the use of a direct path load unless the index is disabled beforehand.
Also note the tiny amounts of undo we are talking about for 50k rows.
SQL> create table t as select * from all_objects where 0 = 1;
Table created.
SQL> insert into t select * from all_objects;
56108 rows created.
SQL> select
2 used_ublk undo_used_blk,
3 used_ublk * blk_size_kb undo_used_kb,
4 log_io logical_io,
5 cr_get consistent_gets
6 from
7 v$transaction, v$session s,
8 (select distinct sid from v$mystat) m,
9 (select to_number(value)/1024 blk_size_kb
10 from v$parameter where name='db_block_size')
11 where
12 m.sid = s.sid
13 and ses_addr = saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
27 216 13893 1042736
SQL> rollback;
Rollback complete.
SQL> insert /*+ append */ into t select * from all_objects;
56108 rows created.
SQL> select
2 used_ublk undo_used_blk,
3 used_ublk * blk_size_kb undo_used_kb,
4 log_io logical_io,
5 cr_get consistent_gets
6 from
7 v$transaction, v$session s,
8 (select distinct sid from v$mystat) m,
9 (select to_number(value)/1024 blk_size_kb
10 from v$parameter where name='db_block_size')
11 where
12 m.sid = s.sid
13 and ses_addr = saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
2 16 1307 1041151
SQL> rollback;
Rollback complete.
SQL> create unique index t_idx on t (object_id);
Index created.
SQL> insert into t select * from all_objects;
56109 rows created.
SQL> select
2 used_ublk undo_used_blk,
3 used_ublk * blk_size_kb undo_used_kb,
4 log_io logical_io,
5 cr_get consistent_gets
6 from
7 v$transaction, v$session s,
8 (select distinct sid from v$mystat) m,
9 (select to_number(value)/1024 blk_size_kb
10 from v$parameter where name='db_block_size')
11 where
12 m.sid = s.sid
13 and ses_addr = saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
88 704 20908 1043193
SQL> rollback;
Rollback complete.
SQL> insert /*+ append */ into t select * from all_objects;
56109 rows created.
SQL> select
2 used_ublk undo_used_blk,
3 used_ublk * blk_size_kb undo_used_kb,
4 log_io logical_io,
5 cr_get consistent_gets
6 from
7 v$transaction, v$session s,
8 (select distinct sid from v$mystat) m,
9 (select to_number(value)/1024 blk_size_kb
10 from v$parameter where name='db_block_size')
11 where
12 m.sid = s.sid
13 and ses_addr = saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
57 456 2310 1041047 -
Needed help in bulk collect using collections
Hi,
I have created a schema level collection like "CREATE OR REPLACE TYPE T_EMP_NO IS TABLE OF NUMBER ;
will i able to use this in a where clause which involves bulk collect?
Please share ur thoughts.
My oracle version is 10guser13710379 wrote:
Will i be able to do a bulk collect into a table using this collection of my sql type?Bulk fetches collects into an array like structure - not into a SQL table like structure. So calling a collection variable in PL/SQL a "+PL/SQL table+" does not make much sense as this array structure is nothing like a table. For the same reason, one needs to question running SQL select statements against PL/SQL arrays.
As for your SQL type defined - it is a collection (array) of numbers. Thus it can be used to bulk fetch a numeric column. -
I need an help regarding Bulk collect
Can we use bulkcollect with sys_refursor ?
for ex :
create or replace procedure sampelpro ( recs out sys_refcursor) is
begin
execute immediate 'select * from table1' bulk collect into recs ;
end sampelpro;
Note : table1 has 1+ laks record
if the above code is not possible then let me know any possible ways ?Hi and welcome to the forum
Can we use bulkcollect with sys_refursor ?No, and you shouldn't.
Your signature says that OUT parameter is a cursor. A cursor is not a resultset, but rather a pointer to one.
So your best choice is probably just to use that, and not try to select into a collection.
Note : table1 has 1+ laks recordEven more important then not to return a collection, but a cursor. (Although I don't remember what a lak is)
Example on how to use:
create or replace procedure sampelpro (recs out sys_refcursor)
is
begin
open recs for 'select empno, ename from emp';
end sampelpro;
Procedure er oprettetAnd a test. Imagine this being a Java client or something the like
SQL> var c refcursor
SQL> exec sampelpro(:c)
PL/SQL-procedure er udf°rt.
SQL> print c
EMPNO ENAME
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
7900 JAMES
7902 FORD
7934 MILLER
14 rµkker er valgt.
SQL>Blushadow has a nice post on cursors here:
PL/SQL 101 : Understanding Ref Cursors
Regards
Peter -
Hi,
below procedure is throwing error like "invalid sql". i doubt problem is with insert statement inside the body of the procedure, please help me how to load table with individual columns in bulk collect
CREATE OR REPLACE PROCEDURE subscriber_load
IS
TYPE r_subscriber_data IS RECORD
( acct_no LPDADMIN.SUBSCRIBER.acct_no%TYPE,
acct_status_cd LPDADMIN.SUBSCRIBER.acct_status_cd%TYPE,
connect_date LPDADMIN.SUBSCRIBER.connect_date%TYPE,
disconnect_date LPDADMIN.SUBSCRIBER.disconnect_date%TYPE,
bill_salutation_cd LPDADMIN.SUBSCRIBER.bill_salutation_cd%TYPE,
bill_first_name LPDADMIN.SUBSCRIBER.bill_first_name%TYPE,
bill_last_name LPDADMIN.SUBSCRIBER.bill_last_name%TYPE,
bill_addr_1 LPDADMIN.SUBSCRIBER.bill_addr_1%TYPE,
bill_addr_2 LPDADMIN.SUBSCRIBER.bill_addr_2%TYPE,
bill_city LPDADMIN.SUBSCRIBER.bill_city%TYPE,
bill_postal_code LPDADMIN.SUBSCRIBER.bill_postal_code%TYPE,
bill_province_cd LPDADMIN.SUBSCRIBER.bill_province_cd%TYPE,
bill_cycle_day LPDADMIN.SUBSCRIBER.bill_cycle_day%TYPE,
home_phone LPDADMIN.SUBSCRIBER.home_phone%TYPE,
business_phone LPDADMIN.SUBSCRIBER.business_phone%TYPE,
first_name LPDADMIN.SUBSCRIBER.first_name%TYPE,
last_name LPDADMIN.SUBSCRIBER.last_name%TYPE,
home_phone LPDADMIN.SUBSCRIBER.home_phone%TYPE,
delql_status_cd LPDADMIN.SUBSCRIBER.delql_status_cd%TYPE,
service_address_1 LPDADMIN.SUBSCRIBER.service_address_1%TYPE,
service_address_2 LPDADMIN.SUBSCRIBER.service_address_2%TYPE,
service_city LPDADMIN.SUBSCRIBER.service_city%TYPE,
service_province_cd LPDADMIN.SUBSCRIBER.service_province_cd%TYPE
TYPE t_subscriber_data IS TABLE OF r_subscriber_data INDEX BY BINARY_INTEGER;
table_subscriber_data t_subscriber_data;
CURSOR c_subscriber_data IS
SELECT s.acct_no
,lb.lob_status_cd
,s.connect_date
,s.disconnect_date
,s.bill_to_salutation_cd
,substr(s.bill_to_name,instr(bill_to_name,',',1)+1) bill_first_name
,substr(s.bill_to_name,1,instr(bill_to_name,',',1)-1) bill_last_name
,s.bill_to_addr_1
,s.bill_to_addr_2
,s.bill_to_city
,s.bill_to_postal_code
,s.bill_to_province_cd
,s.bill_create_day_of_month
,s.home_phone
,s.business_phone
,substr(s.name,instr(bill_to_name,',',1)+1) first_name
,substr(s.name,1,instr(bill_to_name,',',1)-1) last_name
,s.home_phone
,s.delq_status_cd
,h.addr_1
,h.addr_2
,h.city
,h.province_cd
FROM ccsadmin.subscriber s
inner join CCSADMIN.HOUSE h
on s.HOUSE_KEY = h.HOUSE_NO
left outer join CCSADMIN.LINE_OF_BUSINESS lb
on h.HOUSE_NO = lb.HOUSE_NO
WHERE lb.LOB_TYPE_CD ='C'
AND lb.HOUSE_NO IS NOT NULL;
BEGIN
OPEN c_subscriber_data;
LOOP
FETCH c_subscriber_data BULK COLLECT INTO table_subscriber_data LIMIT 100000;
EXIT WHEN table_subscriber_data.COUNT = 0;
if table_subscriber_data.COUNT>0 then
FOR idx IN table_subscriber_data.first..table_subscriber_data.last loop
INSERT INTO LPDADMIN.SUBSCRIBER(acct_no
,acct_status_cd
,connect_date
,disconnect_date
,bill_salutation_cd
,bill_first_name
,bill_last_name
,bill_addr_1
,bill_addr_2
,bill_city
,bill_postal_code
,bill_province_cd
,bill_cycle_day
,home_phone
,business_phone
,first_name
,last_name
,home_phone
,delql_status_cd
,service_address_1
,service_address_2
,service_city
,service_province_cd
VALUES (table_subscriber_data(idx).acct_no
,table_subscriber_data(idx).acct_status_cd
,table_subscriber_data(idx).connect_date
,table_subscriber_data(idx).disconnect_date
,table_subscriber_data(idx).bill_salutation_cd
,table_subscriber_data(idx).bill_first_name
,table_subscriber_data(idx).bill_last_name
,table_subscriber_data(idx).bill_addr_1
,table_subscriber_data(idx).bill_addr_2
,table_subscriber_data(idx).bill_city
,table_subscriber_data(idx).bill_postal_code
,table_subscriber_data(idx).bill_province_cd
,table_subscriber_data(idx).bill_cycle_day
,table_subscriber_data(idx).home_phone
,table_subscriber_data(idx).business_phone
,table_subscriber_data(idx).first_name
,table_subscriber_data(idx).last_name
,table_subscriber_data(idx).home_phone
,table_subscriber_data(idx).delql_status_cd
,table_subscriber_data(idx).service_address_1
,table_subscriber_data(idx).service_address_2
,table_subscriber_data(idx).service_city
,table_subscriber_data(idx).service_province_cd);
END LOOP;
end if;
END subscriber_load;
/no PL/SQL required
INSERT INTO LPDADMIN.SUBSCRIBER(acct_no
,acct_status_cd
,connect_date
,disconnect_date
,bill_salutation_cd
,bill_first_name
,bill_last_name
,bill_addr_1
,bill_addr_2
,bill_city
,bill_postal_code
,bill_province_cd
,bill_cycle_day
,home_phone
,business_phone
,first_name
,last_name
,home_phone
,delql_status_cd
,service_address_1
,service_address_2
,service_city
,service_province_cd
) SELECT ..... -
Please help with an embedded query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
string sql = "INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, " +
"SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, " +
"BENEFICIARY_FIRST_NAME, BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, " +
"CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE, LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, " +
"UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL, ATTENDING_PROVIDER_NUMBER, " +
"BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI) " +
"VALUES " +
"(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs, :REQUEST_METHOD_IDs, " +
":SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs, :SERVICE_LOCATION_STATEs, " +
":BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs, :HICNUMs, :CCNs, " +
":CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs, :CONTRACTOR_IDs, :PRIORITY_IDs, " +
":UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs, :ATTENDING_PROVIDER_NUMBERs, " +
":BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs, :STUDY_IDs, :REFERRING_NPIs) " +
" RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs";
int[] REQUEST_IDs = new int[range];
cmd.Parameters.Add(":REQUEST_IDs", OracleDbType.Int32, REQUEST_IDs, System.Data.ParameterDirection.Output);
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youIt seems you are not doing a bulk insert but rather an array bind.
(Which you will also find that it is problematic to do an INSERT with a bulk collect returning clause (while this works just fine for update/deletes) :
http://www.oracle-developer.net/display.php?id=413)
But you are using array bind, so you simply just need to use a
... Returning REQUEST_ID INTO :REQUEST_IDand that'll return you a Rquest_ID[]
see below for a working example (I used a procedure but the result is the same)
//Create Table Zzztab(Deptno Number, Deptname Varchar2(50) , Loc Varchar2(50) , State Varchar2(2) , Idno Number(10)) ;
//create sequence zzzseq ;
//CREATE OR REPLACE PROCEDURE ZZZ( P_DEPTNO IN ZZZTAB.DEPTNO%TYPE,
// P_DEPTNAME IN ZZZTAB.DEPTNAME%TYPE,
// P_LOC IN ZZZTAB.LOC%TYPE,
// P_State In Zzztab.State%Type ,
// p_idno out zzztab.idno%type
// IS
//Begin
// Insert Into Zzztab (Deptno, Deptname, Loc, State , Idno)
// Values (P_Deptno, P_Deptname, P_Loc, P_State, Zzzseq.Nextval)
// returning idno into p_idno;
//END ZZZ;
//Drop Procedure Zzz ;
//Drop Sequence Zzzseq ;
//drop Table Zzztab;
class ArrayBind
static void Main(string[] args)
// Connect
string connectStr = GetConnectionString();
// Setup the Tables for sample
Setup(connectStr);
// Initialize array of data
int[] myArrayDeptNo = new int[3]{1, 2, 3};
String[] myArrayDeptName = {"Dev", "QA", "Facility"};
String[] myArrayDeptLoc = {"New York", "Chicago", "Texas"};
String[] state = {"NY","IL","TX"} ;
OracleConnection connection = new OracleConnection(connectStr);
OracleCommand command = new OracleCommand (
"zzz", connection);
command.CommandType = CommandType.StoredProcedure;
// Set the Array Size to 3. This applied to all the parameter in
// associated with this command
command.ArrayBindCount = 3;
command.BindByName = true;
// deptno parameter
OracleParameter deptNoParam = new OracleParameter("p_deptno",OracleDbType.Int32);
deptNoParam.Direction = ParameterDirection.Input;
deptNoParam.Value = myArrayDeptNo;
command.Parameters.Add(deptNoParam);
// deptname parameter
OracleParameter deptNameParam = new OracleParameter("p_deptname", OracleDbType.Varchar2);
deptNameParam.Direction = ParameterDirection.Input;
deptNameParam.Value = myArrayDeptName;
command.Parameters.Add(deptNameParam);
// loc parameter
OracleParameter deptLocParam = new OracleParameter("p_loc", OracleDbType.Varchar2);
deptLocParam.Direction = ParameterDirection.Input;
deptLocParam.Value = myArrayDeptLoc;
command.Parameters.Add(deptLocParam);
//P_STATE -- -ARRAY
OracleParameter stateParam = new OracleParameter("P_STATE", OracleDbType.Varchar2);
stateParam.Direction = ParameterDirection.Input;
stateParam.Value = state;
command.Parameters.Add(stateParam);
//idParam-- ARRAY
OracleParameter idParam = new OracleParameter("p_idno", OracleDbType.Int64 );
idParam.Direction = ParameterDirection.Output ;
idParam.OracleDbTypeEx = OracleDbType.Int64;
command.Parameters.Add(idParam);
try
connection.Open();
command.ExecuteNonQuery ();
Console.WriteLine("{0} Rows Inserted", command.ArrayBindCount);
//now cycle through the output param array
foreach (Int64 i in (Int64[])idParam.Value)
Console.WriteLine(i);
catch (Exception e)
Console.WriteLine("Execution Failed:" + e.Message);
finally
// connection, command used server side resource, dispose them
// asap to conserve resource
connection.Close();
command.Dispose();
connection.Dispose();
Console.WriteLine("Press Enter to finish");
Console.ReadKey();
} -
Please help with the query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
VALUES
(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
:REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
:SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
:HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
:CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
:ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
:STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youYou cannot use (and do not want to in this case) the BULK COLLECT.
create table for_testing
the_id number not null primary key,
some_data number
declare
l_return_value for_testing.the_id%type;
begin
4
insert into for_testing
the_id,
some_data
values
1,
5
returning the_id into l_return_value;
dbms_output.put_line('the return values is ' || l_return_value);
end;
20 /
the return values is 1
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable . -
HELP!!! How to print out details in BULK COLLECT?
I have a
select line#, item, price ...
BULK COLLECT into v_line_table
from table_1, table_2
where ....
How can I do dbms_output.put_line from v_line_table, so I can see what value I got?
Please help! Thank youdoesn't seems to recognize the word "COLLECTION"
dbms_output.put_line(COLLECTION.my_column);
I aslo tried FOR LOOP, no luck
FOR x IN 1 .. v_line_table.COUNT
LOOP
dbms_output.put_line('v_line_table.line_discount '|| v_line_table(x).line_discount); */
END LOOP;
please advise -
Please help me on "Bulk Collect"
Hi All,
I've a query like :
select deptno,
min(sal)
from emp;
The above query is taking some 1.2 min to return the expected result of 91k rows and taking cost of 3666.
But when i re written the query like;
select deptno,
min(sal)
from emp where deptno = :dno;
It is giving the correct result & taking very less time,but i need to get the result for all dept's without passing the deptno dynamically.
As per my knowledge i planing to create one function using "Bulk-Collect" and return the all deptno.That result i 've to use in where condition.
But when i trying to create a function i'm not able to do it.. SO can anyone help how to solve the above problem..
How to pass the entire column values in where condition using function..
Do i need to create a function or is there any other way of doing it..
Please help me...
Thanks,
graHi,
I don't follow you when you say that want to get all departments and them pass them back to your query, that makes no sense to me.
If you want max salary for all departments, just:
select deptno, min(sal) min_sal
from emp
group by deptno;No function, no bulk collect no nothing, but plain SQL.
Regards
Peter -
BULK COLLECT using Dynamic PL/SQL???..pls help!!!
Hi All,
Here is PL/SQL block i tried ...unfortunetly failed to execute.
Can anyone put some light on how this can be achieved....no matter even if its a work around job!!
Thanx in advance,
Anita
DECLARE
RCODE VARCHAR2(30):='TBS1B';
RLCODE VARCHAR2(10):='1U6';
RLSQL CLOB;
VSQL CLOB;
TYPE TTABLE IS TABLE OF VARCHAR2(20) INDEX BY BINARY_INTEGER;
TRCODE TTABLE;
BEGIN
SELECT RL_SQL INTO RLSQL FROM COGNOS_RL WHERE RL_CODE=RLCODE;
VSQL:='SELECT DISTINCT '||RCODE||' BULK COLLECT INTO TRCODE FROM CBTABLE WHERE '||RLSQL;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(VSQL));
EXECUTE IMMEDIATE TO_CHAR(VSQL);
END;
ERROR::
03001. 00000 - "unimplemented feature"
*Cause: This feature is not implemented.
*Action: None.Hi,
Try with the following code....
DECLARE
RCODE VARCHAR2(30):='TBS1B';
RLCODE VARCHAR2(10):='1U6';
RLSQL CLOB;
VSQL CLOB;
TYPE TTABLE IS TABLE OF VARCHAR2(20) INDEX BY BINARY_INTEGER;
TRCODE TTABLE;
BEGIN
SELECT RL_SQL INTO RLSQL FROM COGNOS_RL WHERE RL_CODE=RLCODE;
VSQL:='SELECT DISTINCT '||RCODE||' FROM CBTABLE WHERE '||RLSQL;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(VSQL));
EXECUTE IMMEDIATE TO_CHAR(VSQL) BULK COLLECT INTO TRCODE;
END;
Regards,
Sailaja -
Hi All,
I have executed below block in 11g environment.. But getting no results.. My cursor has more than 100 rows.
Can anybody let me know why this is not giving any records.. also is is not giving eny error too.
declare
cursor test_cur is
select d.rp_id,d.date_sent dss,w.date_sent mer
from dw_retl_prds d, web_prds@nrstp w
where d.rp_id = w.rp_rp_id
and ((d.date_sent <> w.date_sent) or
(d.date_sent is null and w.date_sent is not null));
type c1_type is table of test_cur%rowtype;
rec1 c1_type;
begin
open test_cur;
loop
fetch test_cur bulk collect into rec1 limit 10;
exit when rec1.count = 10;
for i in 1 .. rec1.count
loop
dbms_output.put_line(rec1(i).rp_id);
end loop;
end loop;
end;>
Can anybody let me know why this is not giving any records
>
The standard way to exit the loop is to use 'exit when c%notfound' at the end of the loop where 'c' is the cursor name
so use this instead of your code.
loop
fetch test_cur bulk collect into rec1 limit 10;
for i in 1 .. rec1.count
loop
dbms_output.put_line(rec1(i).rp_id);
end loop;
exit when test_cur%notfound;
end loop;See my response Posted: Jan 26, 2012 9:12 AM in response to: Roger at
Re: bulk collect into with limit
declare
type array is table of number index by binary_integer;
l_data array;
cursor c is select empno from emp;
begin
open c;
loop
fetch c bulk collect into l_data limit 14;
if ( c%notfound )
then
dbms_output.put_line
( 'Cursor returned NOT FOUND but array has ' || l_data.count
|| ' left to process' );
else
dbms_output.put_line
( 'We have ' || l_data.count
|| ' to process' );
end if;
exit when c%notfound;
end loop;
close c;
end; -
Any way to use cursor values inside other cursor by bulk collect?
hi,
Is there any way to use cursor get_tables value insdide loop get column if i am using bulk collect in both cursors?
I tried a lot but i am nt able to do it.kindly help...
create or replace procedure MULTIPLE_CURSORS_PROC is
v_owner varchar2(40);
v_table_name varchar2(40);
v_column_name varchar2(100);
cursor get_tables is
select distinct tbl.owner, tbl.table_name
from all_tables tbl
where tbl.owner = 'SYSTEM';
cursor get_columns is
select distinct col.column_name
from all_tab_columns col
where col.owner = v_owner
and col.table_name = v_table_name;
begin
open get_tables;
loop
fetch get_tables into v_owner, v_table_name;
open get_columns;
loop
fetch get_columns into v_column_name;
end loop;
close get_columns;
end loop;
close get_tables;
end ;hi there
Refer this
CREATE OR REPLACE PROCEDURE MULTIPLE_CURSORS_PROC
IS
TYPE scol IS VARRAY (10000) OF VARCHAR2 (32767);
v_table_name scol;
v_column_name scol;
TYPE curtyp IS REF CURSOR;
get_columns curtyp;
CURSOR get_tables
IS
SELECT DISTINCT tbl.table_name
FROM all_tables tbl
WHERE tbl.owner = 'SYSTEM';
BEGIN
OPEN get_tables;
LOOP
FETCH get_tables BULK COLLECT INTO v_table_name;
FOR indx IN v_table_name.FIRST .. v_table_name.LAST
LOOP
SELECT DISTINCT col.column_name
BULK COLLECT
INTO v_column_name
FROM all_tab_columns col
WHERE col.table_name = v_table_name (indx);
FOR ind IN v_column_name.FIRST .. v_column_name.LAST
LOOP
DBMS_OUTPUT.put_line (v_column_name (ind));
END LOOP;
END LOOP;
EXIT WHEN get_tables%NOTFOUND;
END LOOP;
CLOSE get_tables;
END MULTIPLE_CURSORS_PROC;regards
Hitesh -
Error while doing Bulk Collect to a table type
I'm using a Table type to accumulate resultset from a loop and finally return the records in the table type as a ref cursor to the front end.
But when I'm using Bult collect to insert into the table type object it keeps throwing an error
'PLS-00597: expression 'TAB_CALENDAR_AVAIL_RESULTSET' in the INTO list is of wrong type'. Can someone help me to let me know what could be the reason for this error. I'm not able to proceed further, please help.
Here is the code.
CREATE OR REPLACE PACKAGE hotel
AS
TYPE calendar_cursor IS REF CURSOR;
TYPE type_calendar_avail is RECORD(
HOTEL_ID AVAILABILITY_CALENDAR.hotel_id%TYPE,--varchar2(4), --AVAILABILITY_CALENDAR.hotel_id%TYPE,
AVAIL_DATE AVAILABILITY_CALENDAR.AVAIL_DATE%TYPE ,
TOTAL_COUNT number
TYPE type_calendar_avail_resultset IS TABLE OF type_calendar_avail;
tab_calendar_avail_resultset type_calendar_avail_resultset ; -- declare variable of type type_calendar_avail_resultset
PROCEDURE sp_get_calendar_results (
sallhotelswithavaildate VARCHAR2,
ilengthofstay NUMBER,
sorcowner VARCHAR2,
all_unittypes VARCHAR2, --DBMS_SQL.VARCHAR2S
calendar_resultset OUT calendar_cursor
-- tab_calendar_avail_resultset out type_calendar_avail_resultset
PROCEDURE sp_get_calendar_results (
sallhotelswithavaildate VARCHAR2,
ilengthofstay NUMBER,
-- ivariant NUMBER,
sorcowner VARCHAR2,
all_unittypes VARCHAR2, --DBMS_SQL.VARCHAR2S
calendar_resultset OUT calendar_cursor
AS
sbuf VARCHAR2 (200);
sepr VARCHAR2 (1);
shotelwithdate VARCHAR2 (200);
shotelid VARCHAR2 (10);
savaildate VARCHAR2 (8);
sactualavaildate VARCHAR2 (8);
pos NUMBER;
istart NUMBER;
sstartdate VARCHAR2 (8);
senddate VARCHAR2 (8);
squery VARCHAR2 (32767) := '';
sunittypecond VARCHAR2 (500) := '';
sunitdesccond VARCHAR2 (500) := '';
v_unit_cond a_unit_cond;
tempunitcond VARCHAR2 (50) := '';
BEGIN
istart := 1;
LOOP
tempunitcond := hotel.stringtokenizer (all_unittypes, istart, '|');
IF tempunitcond IS NOT NULL
THEN
v_unit_cond (istart) := tempunitcond;
istart := istart + 1;
END IF;
EXIT WHEN tempunitcond IS NULL;
END LOOP;
sunitdesccond := hotel.get_unit_description_cond (v_unit_cond);
DBMS_OUTPUT.put_line ('unit description : ' || sunitdesccond);
sbuf := sallhotelswithavaildate;
sepr := '|';
istart := 1;
LOOP
shotelwithdate := hotel.stringtokenizer (sbuf, istart, sepr);
EXIT WHEN shotelwithdate IS NULL;
shotelid :=
SUBSTR (shotelwithdate, 1, INSTR (shotelwithdate, ',') - 1);
savaildate :=
SUBSTR (shotelwithdate, INSTR (shotelwithdate, ',') + 1);
squery :=
' SELECT MIN (ad.avail_date) '
|| ' FROM wvo_fonres.fpavail_daily ad'
|| ' WHERE ad.hotel_id = '
|| shotelid
|| ' AND ad.days_left >= '
|| ilengthofstay
|| ' AND ad.avail_date >= '
|| savaildate;
IF UPPER (sorcowner) = 'N'
THEN
squery :=
squery
|| ' AND ad.ORC_TYPE != ''R'' and ad.ORC_TYPE != ''P'' and ad.ORC_TYPE != ''E'' ';
END IF;
squery := squery || ' AND ( ' || sunitdesccond || ') ';
EXECUTE IMMEDIATE squery
INTO sactualavaildate;
DBMS_OUTPUT.put_line ('Actual available Date: ' || sactualavaildate);
hotel.sp_get_startdate_enddate (sactualavaildate,
--ivariant,
sstartdate,
senddate
sunittypecond := hotel.get_unittype_cond (v_unit_cond, sorcowner);
-- execute immediate
squery :=
'select HOTEL_ID, AVAIL_DATE, ' || sunittypecond || ' AS TOTAL_COUNT '
|| ' FROM AVAILABILITY_CALENDAR A '
|| 'WHERE '
|| 'AVAIL_DATE >= '''
|| sstartdate
|| ''' '
|| 'AND '
|| 'AVAIL_DATE <= '''
|| senddate
|| ''' '
||'AND '
|| 'A.HOTEL_ID IN ('
|| shotelid
|| ') '
|| 'AND ('
|| sunittypecond
|| '> 0) '
|| -- where total available count of unit type is greater than 0
' ORDER BY AVAIL_DATE'; --order clause
open calendar_resultset for squery;
fetch calendar_resultset BULK COLLECT INTO tab_calendar_avail_resultset;
istart := istart + 1;
END LOOP;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line
(SQLERRM (SQLCODE));
RAISE;
END sp_get_calendar_results;
END hotel;
/1. put tags [co[/b][b]de] and [co[/b][b]de] around your code, so it's readable
B. what does "hotel.get_unittype_cond (v_unit_cond, sorcowner)" actually retun?
and third, try this for the array declaration:
tab_calendar_avail_resultset type_calendar_avail_resultset := type_calendar_avail_resultset ; () ; -
ORA-01722: invalid number error with Bulk collect
Hi ,
I have been using the script to delete old seasonal data from my application DB tables. The stored procedure has been created successfully but when i try to run the proc it has been throwing 'ORA-01722: invalid number' exception at line 'FETCH C1_CUR BULK COLLECT INTO C1_TYPE_VAR LIMIT v_bulklimit;'.
Could you please help me here?
Below is the stored proc:
CREATE OR REPLACE PROCEDURE clean_old_season_data(P_SEASON VARCHAR2) AS
CURSOR C1_CUR IS SELECT ROWID RID,pro.* FROM PROPS pro where pro.ITEMPK IN
(SELECT sve.pk FROM SAVEDVALUEENTRY sve WHERE sve.p_parent IN
(SELECT s.pk FROM SAVEDVALUES s WHERE s.P_MODIFIEDITEM IN
(SELECT a.PK
FROM products a
WHERE a.p_season IN (select s.pk from Seasons s where s.P_code=P_SEASON)
) ) ) and rownum<5;
CURSOR C2_DEL IS SELECT RID FROM PROPS_HISTORY;
TYPE C1_TYPE IS TABLE OF C1_CUR%ROWTYPE;
C1_TYPE_VAR C1_TYPE;
TYPE C2_TYPE IS TABLE OF UROWID;
C2_TYPE_VAR C2_TYPE;
ex_dml_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(ex_dml_errors, -24381);
l_error_count NUMBER;
err_num NUMBER;
err_msg VARCHAR2 (300);
COMMIT_VARIABLE PLS_INTEGER:=0;
v_bulklimit NUMBER:=2;
BEGIN
/*------------------ Data Selection and INSERTION IN HISTORY TABLE ---------------------------------------*/
OPEN C1_CUR;
LOOP
DBMS_OUTPUT.put_line('Cursor opend now in loop');
FETCH C1_CUR BULK COLLECT INTO C1_TYPE_VAR LIMIT v_bulklimit;//ERROR OCCURS HERE
DBMS_OUTPUT.put_line('Cursor count is'|| C1_TYPE_VAR.COUNT);
FORALL I IN 1..C1_TYPE_VAR.COUNT SAVE EXCEPTIONS
INSERT INTO PROPS_HISTORY VALUES C1_TYPE_VAR(I);
COMMIT_VARIABLE := COMMIT_VARIABLE + v_bulklimit;
DBMS_OUTPUT.put_line('Commit variable'|| COMMIT_VARIABLE.COUNT);
IF COMMIT_VARIABLE = v_bulklimit THEN
COMMIT;
COMMIT_VARIABLE := 0;
END IF;
EXIT WHEN C1_CUR%NOTFOUND;
END LOOP;
DBMS_OUTPUT.put_line('Cursor closed now in loop and data inserted in history table');
CLOSE C1_CUR;
/*------------------ Data Selection and DELETION IN Live TABLE ---------------------------------------*/
COMMIT_VARIABLE := 0;
OPEN C2_DEL;
LOOP
FETCH C2_DEL BULK COLLECT INTO C2_TYPE_VAR LIMIT 2;
FORALL I IN 1..C2_TYPE_VAR.COUNT SAVE EXCEPTIONS
DELETE FROM PROPS WHERE ROWID = C2_TYPE_VAR(I);
COMMIT_VARIABLE := COMMIT_VARIABLE + 2;
IF COMMIT_VARIABLE = 2 THEN
COMMIT;
COMMIT_VARIABLE := 0;
END IF;
EXIT WHEN C2_DEL%NOTFOUND;
END LOOP;
CLOSE C2_DEL;
END;Although there are many things which should not have been done in the posted code, I could not find any reason why the Invalid number error should occur at the Fetch clause.
I would suggest you to Insert into Table by providing the Order of Columns i.e. Insert into table (col1, ... colN) values (coll(i).col1...col(i).colN);
I tested below code and it did not give any errors.
drop table test_table;
create table test_Table
rid varchar2(100),
emp_id number(5),
fname varchar2(20),
lname varchar2(50)
set serveroutput on;
declare
cursor c_cur is
select rowid rid, e.*
from employees e
where rownum < 10;
type typ_cur is table of c_cur%rowtype;
typ typ_cur;
l_bulk_limit number := 5;
begin
open c_cur;
loop
fetch c_cur bulk collect into typ limit l_bulk_limit;
dbms_output.put_line('Collection Count :: ' || typ.count);
forall i in 1..typ.count --typ.first..typ.last
insert into test_Table (rid, emp_id, fname, lname) values (typ(i).rid,typ(i).employee_id,typ(i).first_name,typ(i).last_name);
dbms_output.put_line('Processed ' || l_bulk_limit || ' records.');
exit when c_cur%notfound;
end loop;
commit;
end;
select * from test_table;PS:- 1. When you are processing only 4 Records, then why are you breaking them in 2 Loops?
2. Why Commit every time you are processing a DML? Why not maintain an Error Flag and Rollback the Transaction as soon as error is encountered?
3. Use "{code}" (Exclude Double Quotes) to format the code. I am not sure if works.
Regards,
P.
Maybe you are looking for
-
The hp printer control app can not find my eprint email.
I have an iPad 2 and I've installed the hp printer control app on it. The app can not find my eprint email which I've typed in several times. I have checked the eprint email on the printer control panel to make sure it is the correct eprint email. Th
-
I upgraded to v3.6.22 today and have lost the ability to ctrl-click a link to open the link in a new tab; how do I get this back?
-
Connect unmanaged clients to Software Update Services 10.8.4
Software Update Services 10.8.4 I cannot get unmanaged clients to connect to my ML Software Update Service I tried the following versions: sudo defaults write com.apple.SoftwareUpdate CatalogURL http://my.sus.local:8088/ sudo defaults write com.apple
-
Hello, I have a list with around 25 items. The appearance of an item is defined in FXML and I use cellFactory of that list to create those items. The item class looks as follows: public class MatchCell extends ListCell<MatchModel> { @Override
-
Hello! I'm trying to figure out how to update my a row in my DataGridView. As you can see in my codes, I basically just remade my INSERT statement and changed it to UPDATE. I'm aware of this and I knew it wouldn't work, but how can I update my datagr