Collect in bulk
Hi all
I want to pick only 10 records at a time. It is extracted all 14 records why? I need only 10 records, if I had no please let me help.
DECLARE
CURSOR emp_cur IS
SELECT empno,
ename ,
job
FROM emp;
TYPE emp_no_type IS TABLE OF emp. EmpNo % TYPE ;
TYPE emp_name_type IS TABLE OF emp. Ename % TYPE ;
TYPE job_name_type IS TABLE OF emp. job % TYPE ;
emp_no_tab EMP_NO_TYPE
emp_name_tab EMP_NAME_TYPE
job_name_tab JOB_NAME_TYPE
v_limit PLS_INTEGER := 10;
START
OPEN emp_cur;
LOOP
-Get 10 rows at a time
FETCH emp_cur bulk collect INTO emp_no_tab, emp_name_tab, job_name_tab
limit
v_limit ;
EXIT WHEN emp_no_tab. County = 0;
FOR i IN emp_no_tab. first .. emp_no_tab . last LOOP
dbms_output . Put_line ('Emp Number: ' || Emp_no_tab (i) );
dbms_output . Put_line ('Emp Name: ' || Emp_name_tab (i) );
dbms_output . Put_line ('Emp Job: ' || Job_name_tab (i) );
END LOOP;
END LOOP;
CLOSE emp_cur;
END ;
Thank U
994122 wrote:
Thank you..
Ensure?
What happens when the EMP table contains 24 ranks?
Do not rely on the attributes of the cursor with bulk collect (PL/SQL practices: COLLECT in BULK)
Just drag the outer loop, (because what you want to do, it's to combat by setting the limit only) and the exit condition:
OPEN emp_cur;
-LOOP
-Go get 10 lines at a time
Collect the FETCH emp_cur in bulk IN emp_no_tab, emp_name_tab, job_name_tab
limit
v_limit;
-EXIT WHEN emp_no_tab.count = 0;
I'm IN emp_no_tab.first... emp_no_tab. Last LOOP
dbms_output. Put_line ('Emp number: ' |) Emp_no_tab (i));
dbms_output. Put_line (' Name of Emp: ' |) Emp_name_tab (i));
dbms_output. Put_line ('Emp Job: ' |) Job_name_tab (i));
END LOOP;
-END LOOP;
CLOSE Emp_cur;
Tags: Database
Similar Questions
-
Dear all,
I try to use bulk collect for one of my requirements. I defined a procedure and using bulk collect inside.
The procedure is the compilation of the warnings.
The error message is "PLS-00487: invalid reference to the variable 'I'".
Here is the procedure I use.
----------------------------------
CREATE OR REPLACE procedure APPS.XXX_MRP_PAY4 (RETCODE OUT VARCHAR2,
ERRBUF OUT VARCHAR2
-P_SERVICE_CALC_DATE IN DATE,
-P_VARIABLE IN NUMBERS
)
is
-L_VARIABLE NUMBER: = P_VARIABLE;
cursor c1 is
SELECT
EMPLOYEE_NUMBER
FULL_NAME
OF XX_MRP_SALARY_BREAKUP SB,
sit_date sd
where = SB.employee_number sd.emp_num (+);
TYPE MRP_RESULTS IS TABLE OF c1% ROWTYPE INDEX BY PLS_INTEGER;
MRP MRP_RESULTS;
CLOB L_TEXT;
Start
FND_FILE.put_line (FND_FILE.output, 'EMPLOYEE_NUMBER' |) CHR (9) | "FULL_NAME");
-I'm looping C1
OPEN c1;
LOOP
FETCH c1
BULK COLLECT INTO MRP LIMIT 1500;
WHEN THE MRP OUTPUT. COUNT = 0;
because me in 1... MRP. COUNTY
loop
L_TEXT: = I.EMPLOYEE_NUMBER | Chr (9) | I.FULL_NAME;
FND_FILE.put_line (FND_FILE.output, L_TEXT);
end loop;
END LOOP;
CLOSE c1;
end XXX_MRP_PAY4;
-------------------------------
You kindly could guide me on this plssSeems you placed a CURSOR for... LOOP in a COLLECTION in BULK.
The variable 'i' used to be a record, but now it's a number.
Suspect you want...
l_text := mrp (i).employee_number || CHR (9) || mrp (i).full_name;
-
Collect in bulk does not print the results in the table
Then the PL/SQL block below do not load and print whatever it is:
-Database 11 g:
declare
Type (vr_Rec) is rendered
DESCRIPTION VARCHAR2 (100)
QTDE NUMBER (2));
Type vt_Rec index vr_Rec table of Pls_Integer;
va_rec vt_Rec;
vc_Cursor SYS_REFCURSOR;
Start
Vc_Cursor open for 'SELECT "x" DESCRIPTION, 1 QTDE FROM DUAL UNION ALL' |
"SELECT the"y"DESCRIPTION, 2 QTDE FROM DUAL;
Loop
Get the vc_Cursor collect in bulk va_rec limit 20000;
When the output va_rec. Count = 0;
End loop;
Close Vc_Cursor;
If va_rec > 0 Then Count.
For / * everything * / i in va_rec. first... va_rec. last loop
dbms_output.put_line (va_rec (i). DESCRIPTION | ' - ' || va_rec (i). QTDE);
End loop;
End If;
end;lucitah wrote:
Then the PL/SQL block below do not load and print whatever it is:Yes, this isn't. Look at the code. Each extraction replaces data read by the previous fetch. And since he finished when va_rec. Count = 0, we are left with empty va_rec. You need something like:
declare Type vr_Rec Is Record ( DESCRICAO VARCHAR2(100) , QTDE NUMBER(2) ); Type vt_Rec Is table of vr_Rec Index By Pls_Integer; va_rec vt_Rec; vc_Cursor SYS_REFCURSOR; begin Open vc_Cursor For 'SELECT ''x'' DESCRICAO, 1 QTDE FROM DUAL UNION ALL '|| 'SELECT ''y'' DESCRICAO, 2 QTDE FROM DUAL'; Loop Fetch vc_Cursor Bulk Collect Into va_rec Limit 20000; Exit When va_rec.Count = 0; For i In va_rec.First..va_rec.Last Loop dbms_output.put_line( va_rec(i).DESCRICAO || ' - ' || va_rec(i).QTDE ); End Loop; End Loop; Close vc_Cursor;
SY.
-
Need help with debugging collection in bulk and loop forall
Hi people,
I was wondering if someone can look at my PL/SQL code and tell me where I'm wrong.
Environment
=========
10g (Rel 2)
Algorithm of
=======
A slider lets collect records
The data block
Bulk insert the data into a table
Implementation
==========
Set serveroutput on;
declare
cursor source_cur is
Select * from
from t1;
-Define the variables and collection types to be used by the BULK COLLECT clause
source_data_type type is the table of the source_cur % rowtype;
source_data_table source_data_type;
Start
Open source_cur;
loop
extraction source_cur
bulk collect into source_data_table;
When the output source_data_table.count = 0;
-Now, we print the data collected
-for i in source_data_table.first... source_data_table. Last
-loop
-dbms_output.put_line (' company name: ' | source_data_table (i).) Company);
-dbms_output.put_line ('Count: ' | source_data_table.) (COUNT);
-end loop;
end loop;
close source_cur;
Note: The statements above Print print the correct data and County
-Now, bulk insert us the data into the target table
dbms_output.put_line ('Count: ' | source_data_table.) (COUNT);
Note: The print statement above indicates a number 0 =. Since there is no available record, FORALL loop below will not insert anything in the table
ForAll idx in source_data_table. FIRST... source_data_table. LAST
Insert into T2
source_data_table (idx) values;
end;
/
Thanks in advance
rogers42You'll want to do something like this
open source_cur; loop fetch source_cur bulk collect into source_data_table; exit when source_data_table.count = 0; forall idx in source_data_table.FIRST .. source_data_table.LAST insert into T2 values source_data_table(idx); end loop; close source_cur;
or even better:
insert into target select col, col, col from source
no need to COLLECT in BULK and FORALL
;) -
SP2-0552 error in Collections in bulk
Im trying to run this piece of code, but get an error such as displayed below;
-COLLECTIONS IN BULK
DECLARE
CURSOR v_bulk IS
SELECT employee_id
Employees;
TYPE c_array IS TABLE OF v_bulk % ROWTYPE
INDEX BY PLS_INTEGER;
v_array c_array;
BEGIN
OPEN v_bulk.
LOOP
Get the v_bulk COLLECT LOOSE v_array LIMIT 100;
EXIT WHEN v_bulk % NOTFOUND;
DBMS_OUTPUT. Put_line (v_array);
END OF LOOP:
CLOSE V_bulk;
END;
/
Error: Variable binding of the SP2-0552 'CLOSE' not stated
Please help me on this.
Thanks in advance.: after the end of the loop.
should be;
alvinder
-
ORA-00947: not enough values error collect in bulk
Hi guys,.
I'm trying to COLLECT in a PL/SQL table, but I get ORA-00947: not enough values error message, even if the table has 4 values and select 4 values. Am I missing something?
I have to add something to this?
I've included the types of database objects that I created on the database.
I have commented on the Original code and used the table DOUBLE just to make simple workout.
/*
CREATE or REPLACE TYPE Usage_Groups_for_coda_rec as
object
(Usage_Group_ID NUMBER (10),)
Coda_comment VARCHAR2 (45).
Amount NUMBER,
Deduction_amount NUMBER);
CREATE OR REPLACE
TYPE USAGE_GROUPS_FOR_CODA_TAB AS
TABLE OF Usage_Groups_for_coda_rec;
*/
declare
-CURSOR c_adj_roy_trans
-EAST
-SELECT DISTINCT rotr.on_behalf_of_soc_nbr, rotr.right_type
-OF royalty_transaction rumble
-WHERE rotr.ps_adjust_royalty_flg = cm_default.get_yes;
CURSOR c_adj_roy_trans
IS
SELECT '052', 'P '.
DOUBLE;
t_uge_Grp_for_coda_tab USAGE_GROUPS_FOR_CODA_TAB; -the type of table was created on the database
Start
FOR r_adj_roy_trans IN c_adj_roy_trans LOOP
-SELECT rotr.usage_group_id as Usage_Group_ID,
-cm_coda_account_default.get_canc_adj_coda_comment | '- CAE' as Coda_comment,
-SUM (NVL (rotr.gross_amt, 0) + NVL (rotr.reciprocal_deduction_amt, 0)) as an amount
-SUM (rotr.reciprocal_deduction_amt) as Deduction_amount
-COLLECT LOOSE t_uge_Grp_for_coda_tab
-OF royalty_transaction rumble
-WHERE rotr.ps_adjust_royalty_flg = cm_default.get_yes
- AND rotr.on_behalf_of_soc_nbr = r_adj_roy_trans.on_behalf_of_soc_nbr
- AND rotr.right_type = r_adj_roy_trans.right_type
-Rotr.usage_group_id group;
SELECT 6874534 as Usage_Group_ID,
"This is a test - CAE" as Coda_comment.
100 as an amount
50 as Deduction_amount
LOOSE COLLECTION t_uge_Grp_for_coda_tab
DOUBLE;
/*
IF l_uge_Grp_for_coda_tab. COUNT > 0 THEN
cm002p.std_coda_post_cashing_out_bulk (p_on_behalf_of_society_number = > r_adj_roy_trans.on_behalf_of_soc_nbr,)
p_right_type = > r_adj_roy_trans.right_type,
p_Usage_Groups_for_coda_tab = > t_uge_Grp_for_coda_tab,
p_reverse_posting_direction = > FALSE,
p_posting_override_direction = > NULL,
p_cohi_id = > NULL
);
END IF;
*/
END LOOP;
end;
Here's what you need to do:
SELECT Usage_Groups_for_coda_rec(6874534, "It is a test - CAE", 100, 50)
LOOSE COLLECTION t_uge_Grp_for_coda_tab
DOUBLE;
You try bulk collect into a collection of Usage_Groups_for_coda_recs, then you will need to make type compatible using the implicit of the type constructor.
-
Use with need to collect in bulk to insert records from multiple tables
Hello
I plsql record type with several tables with multiple columns. so when I used bulk collect with education for ALL. I want to insert records in multiple tables.
Please give me suggestions.
ForAll is designed to be used with a single DML statement, which may include dynamic SQL statements. However, I do not know what advantage this will give you your list iteration save several times, one for each table - especially since there is an air show with SQL dynamic.
Example 1 (dynamic SQL):
begin
...
forall i in vRecList.First..vRecList.Last
execute immediate '
begin
insert into Table1 (Col1, Col2, Col3) values (:1, :2, :3);
insert into Table2 (Col1, Col2, Col3) values (:1, :2, :3);
end;' using vRecList(i).Col1, vRecList(i).Col2, vRecList(i).Col3;
end;Another approach that I should work (but not tested) is using to insert all the Scriptures and based record inserts, but you need to try on your version of Oracle forall has changed between the versions. In this case vRecList must be compatible with the Table % ROWTYPE and Table2% ROWTYPE type.
Example 2 (insert all):
begin
...
forall i in vRecList.First..vRecList.Last
insert all
into Table1 values vRecList(i)
into Table2 values vRecList(i)
select 1 from dual;
end; -
Update of table after SELECT COLLECT in BULK IN
Hello
I have the following query
SELECT TYPE(A, B, C, D) BULK COLLECT INTO ARRAY_TYPE_VAR FROM table WHERE ROWNUM <= number;
And after execution of this I need to update the selected lines to mark as processed.
UPDATE table SET is_proc = 'Y' WHERE ...
-I want to just select a predefined number of lines (ROWNUM < = number)
-Selected data comes from an intermediate table that I can't control and there is no PKs.
Is it possible that I can use to identify the selected lines and use them in an UPDATE statement?
Thank you
Hugo
I need to select the data to perform certain operations and validations and insert in the paintings of application.
Since I have a large number of files, I found myself with performance while loading problems all in memory.
I am trying to create a kind of limiting process:
Until I have 0 not dealt with the lines:
Select lines of high x-> perform data operations-> lines of the selected mark as processed
The sql code I posted is inside a loop.
I'm probably complicate an easy problem, but I'm kinda stuck with it.
And Yes, there is a column that can be used to identify the data.
There is NO NEED to 'Butterfly' lines of process or as treated brand.
Assuming that you need to use the collections and PL/SQL just treat ALL lines but only a limited number at the time.
Some examples of code (ONLY for the demonstration) which deals with the entire EMP table a few lines at a time:
EXTRACTION is a BULK of COLLECTING all the data in "v". It will get either all data, or none if there is none.
The construction of the LOOP would be used when you have a LIMIT clause while Oracle would be 'loop' return to
Download the following set of lines. Run this example in the SCOTT schema and you will see how the LIMIT clause.
I have 14 rows in my table EMP.DECLARE
CURSOR c1 IS (SELECT * FROM emp);
TYPE typ_tbl IS TABLE c1% rowtype;
v typ_tbl;
BEGIN
OPEN c1;
LOOP --Loop added
C1 FETCH BULK COLLECT IN v LIMIT 3; -treat 3 records at a time
-treat the first 3 max records
DBMS_OUTPUT. Put_line ('Treatment' | v.COUNT |) "documents.");
I'm IN v.first... v.Last LOOP
DBMS_OUTPUT. Put_line (v (i) .empno);
END LOOP;
OUTPUT WHEN c1% NOTFOUND;
END LOOP;
DBMS_OUTPUT. Put_line ('all done');
END;In the loop, you would do any processing of the nested table, you want to make
and could use a FORALL do one INSERT into another table. -
Cursor cursor to COLLECT in BULK and test
Hello
I am struggling to test a cursor, my requirement is as follows
To truncate a table then reinsert this record with all the content of the cursor if cursor returns record.
PROCEDURE populate_offline_table AS
CURSOR ext_table_cursor
IS
SELECT * from ext_table;
ARRAY TYPE IS TABLE of ext_table_offline % ROWTYPE;
ext_table_array TABLE.
ext_table_empty EXCEPTION;
BEGIN
OPEN ext_table_cursor.
IF ext_table_cursor % ROWCOUNT > 0 THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE ext_table_offline';
LOOP
Get the ext_table_cursor COLLECT LOOSE ext_table_array LIMIT 1000;
EXIT WHEN ext_table_cursor % NOTFOUND;
FORALL rec IN 1.ext_table_array. COUNTY
INSERT INTO ext_table_offline VALUES (rec) ext_table_array;
END LOOP;
ON THE OTHER
RAISE ext_table_empty;
END IF
CLOSE Ext_table_cursor;
EXCEPTION
WHEN ext_table_empty
THEN dbms_output.put_line ('outer Table is empty');
END populate_offline_table;
Can someone help me please
2726801 wrote:
I have some questions:
1. What is the disadvantages of using slider with BULK COLLECT and LIMIT?
This isn't a slow line according to the treatment, and after treatment. The term "bulk collect" is not a magic formula that transforms the transformation of the slow line in function in evolutionary and optimal treatment.
If you move/copy data from a database table to the other, and you use the PL/SQL engine and the memory of PL/SQL to transfer data from a target SQL to another, it is neither optimal or scalable.
Remove the PL/SQL engine called detour and DIRECTLY copy/move the target of SQL source data to the target SQL, optimal and scalable.
-
Collect in bulk in stores less number of lines in the collection when you use the LIMIT?
I wrote the following PL SQL anonymous block. However, the line dbms_output.put_line (total_tckt_col. FINALLY gives me) output as 366 (DBMS_OUTPUT is Developer SQL) which is correct when there is no limit. If the limit is set at 100 in the FETCH statement then dbms_output.put_line (total_tckt_col. Give me FINALLY) 66. What I'm doing wrong here?
DECLARE
CURSOR cur_total_tckt
is
select t.ticket_id ticket_id, t.created_date created_date, t.created_by created_by, t.ticket_status ticket_status,
t.last_changed last_changed, h.created_date closed_date
from n01.cc_ticket_info t
inner join n01.cc_ticket_status_history h
on (t.ticket_id = h.ticket_id)
where t.last_changed >= '6/28/2012 17:28:59' and t.last_changed < (sysdate + interval '1' day);
type total_tckt_colcn
is
TABLE OF cur_total_tckt%rowtype;
total_tckt_col total_tckt_colcn;
total_coach_col total_tckt_colcn;
begin
total_tckt_col := total_tckt_colcn ();
total_coach_col := total_tckt_colcn ();
OPEN cur_total_tckt;
loop
fetch cur_total_tckt bulk collect into total_tckt_col;
-- fetch cur_total_tckt bulk collect into total_tckt_col limit 100;
EXIT
WHEN (cur_total_tckt%NOTFOUND);
END LOOP ;
CLOSE cur_total_tckt;
dbms_output.put_line(total_tckt_col.LAST);
FOR i IN total_tckt_col.first..total_tckt_col.last
LOOP
dbms_output.put_line(i);
END LOOP;
end;Jocelyn says:
This is a modified version of your code on the standard table EMP in schema scott.
Have you tested it? All you have is last batch has 4 rows. But you print outsite the loop. That way if the last batch is incomplete (within boundary lines) last batch does not have your loop. Suppose you want to print the enames:
DECLARE
CURSOR cur_total_tckt
IS
Select ename
EMP; -I have a total of 14 records in this table
type total_tckt_colcn
is
TABLE OF THE cur_total_tckt % rowtype;
total_tckt_col total_tckt_colcn;
BEGIN
total_tckt_col: = total_tckt_colcn ();
OPEN cur_total_tckt.
LOOP
Cur_total_tckt fetch bulk collect within the limits of the total_tckt_col 5;
EXIT WHEN cur_total_tckt % NOTFOUND;
FOR v_i IN 1.total_tckt_col.count LOOP
dbms_output.put_line (total_tckt_col (v_i) .ename);
END LOOP;
END LOOP;
CLOSE Cur_total_tckt;
END;
/
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNERPL/SQL procedure successfully completed.
SQL >
As you can see, it didn't print the last batch. Why? Because NOTFOUND is set to true if the number of lines that you asked to fetch was not recovered. This last batch has 4 rows while the claim code to get 5. Therefore, NOTFOUND has the value true and outputs code before dealing with this last batch. Therefore, repeat the treatment code again once outside the loop:
DECLARE
CURSOR cur_total_tckt
IS
Select ename
EMP; -I have a total of 14 records in this table
type total_tckt_colcn
is
TABLE OF THE cur_total_tckt % rowtype;
total_tckt_col total_tckt_colcn;
BEGIN
total_tckt_col: = total_tckt_colcn ();
OPEN cur_total_tckt.
LOOP
Cur_total_tckt fetch bulk collect within the limits of the total_tckt_col 5;
EXIT WHEN cur_total_tckt % NOTFOUND;
FOR v_i IN 1.total_tckt_col.count LOOP
dbms_output.put_line (total_tckt_col (v_i) .ename);
END LOOP;
END LOOP;
FOR v_i IN 1.total_tckt_col.count LOOP
dbms_output.put_line (total_tckt_col (v_i) .ename);
END LOOP;
CLOSE Cur_total_tckt;
END;
/
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLERPL/SQL procedure successfully completed.
SQL >
But you have to accept to repeat that twice the processing code is no better solution. When you use BULK COLLECT LIMIT we should not leave NOTFOUND but rather by collection.count = 0:
DECLARE
CURSOR cur_total_tckt
IS
Select ename
EMP; -I have a total of 14 records in this table
type total_tckt_colcn
is
TABLE OF THE cur_total_tckt % rowtype;
total_tckt_col total_tckt_colcn;
BEGIN
total_tckt_col: = total_tckt_colcn ();
OPEN cur_total_tckt.
LOOP
Cur_total_tckt fetch bulk collect within the limits of total_tckt_col 6;
WHEN OUTPUT total_tckt_col.count = 0;
FOR v_i IN 1.total_tckt_col.count LOOP
dbms_output.put_line (total_tckt_col (v_i) .ename);
END LOOP;
END LOOP;
CLOSE Cur_total_tckt;
END;
/
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLERPL/SQL procedure successfully completed.
SQL >
SY.
-
Select the distinct value of a column in the collection in bulk.
Hi all
Collecting the data of a query to a variable of type table. I need to select a separate of a perticular column value in the collection.
Collection has followiing values inside.
I need to select distinct column values (for example: Col (c) .sourcecode) collection and the need to insert in the table if the value in this column does not exist in the table.Col(c).articleid, Col(c).userkey, Col(c).origin, Col(c).addnlorigindata, Col(c).avdest, Col(c).dispfmt, Col(c).sourcecode, Col(c).success_ind, Col(c).error_code, Col(c).entry_createddate, Col(c).createdby, Col(c).filenumber, Col(c).linenumber, Col(c).acctnum, Col(c).assetkey, Col(c).autocompletedterm, Col(c).accessionnumber, Col(c).requestdatetime, Col(c).requestorip, Col(c).articleordinal, Col(c).userinitiatedind, Col(c).captchastatus
Say, Col (c) .sourcecode has the value XYZ, ABC. If the "XYZ" value does not exist in the table, so I need to insert in the table and if "ABC" exists in the tables then don't insert it. (something like fusion) after seecting to the distinct values in a column in the collection.
Thanks n regards
Nana Akkivalli.The collection must be inserted before you can use this topic.
In the Begin block, you have to collect a loose and insert inside: something like
SELECT * BULK COLLECT INTO l_array FROM ALL_USER ...CONDITIONS...
-
literal does not format string when collecting in bulk.
Hello
should work with 10.2 DB.
Just try to display loop a few output of v$ log view :).1 declare 2 type vcArray is table of varchar2(10); 3 type vdateArray is table of date; 4 l_group# vcArray; 5 l_status vcArray; 6 l_date vdateArray; 7 cursor c is select to_char(sysdate, 'YYYYMMDD_HH24MISS') data, GROUP# , status from v$log; 8 begin 9 open c; 10 loop 11 fetch c bulk collect into l_date, l_group# , l_status; 12 for i in 1..l_date.count 13 loop 14 dbms_output.put_line('l_date: ' || l_date(i)); 15 end loop; 16 exit when c%notfound; 17 end loop; 18 close c; 19* end; declare * ERROR at line 1: ORA-01861: literal does not match format string ORA-06512: at line 11
Concerning
GregGHello
GregG says:
Hello
should work with 10.2 DB.1 declare 2 type vcArray is table of varchar2(10); 3 type vdateArray is table of date; 4 l_group# vcArray; 5 l_status vcArray; 6 l_date vdateArray; 7 cursor c is select to_char(sysdate, 'YYYYMMDD_HH24MISS') data, GROUP# , status from v$log; 8 begin 9 open c; 10 loop 11 fetch c bulk collect into l_date, l_group# , l_status; 12 for i in 1..l_date.count 13 loop 14 dbms_output.put_line('l_date: ' || l_date(i)); 15 end loop; 16 exit when c%notfound; 17 end loop; 18 close c; 19* end; declare * ERROR at line 1: ORA-01861: literal does not match format string ORA-06512: at line 11
Just try to display loop a few output of v$ log view :).
Concerning
GregGTo_char, as the name suggests, returns a VARCHAR2, c.data is therefore a VARCHAR2, but you try to store it in an array of DATEs.
Do not use TO_CHAR. In fact, there is no need to use a column for that at all, because SYSDATE will always be the same.Try something like this:
declare type vcArray is table of varchar2(10); l_group# vcArray; l_status vcArray; cursor c is select GROUP# , status from v$log; run_time DATE; begin open c; loop run_time := SYSDATE; fetch c bulk collect into l_group# , l_status; for i in 1..l_group#.count loop dbms_output.put_line('run_time: ' || run_time); end loop; exit when c%notfound; end loop; close c; end; /
Published by: Frank Kulash on 12 March 2012 10:26
Added example. -
UNION ALL in COLLECTION in BULK
My code is like this:SELECT COL_NAME, COUNT BULK COLLECT INTO v_collections FROM ( SELECT 'PROD_NAME' COL_NAME, COUNT(*) COUNT FROM TEST_TABLE WHERE LENGTH(PROD_NAME)>50 UNION ALL SELECT 'PROD_DESC' COL_NAME, COUNT(*) COUNT FROM TEST_TABLE WHERE PROD_DESC IS NULL . . . ..10 MORE UNION ALL ); {code} --does it lead to one context switch or multiple one for each select in the union all --I do want to capture # of errors for each column --although the code runs very fast, still I am worried that it may not be a good coding practice. --is there any better way to do this? --TEST_TABLE has 1 million records Thanks, RN
>
-causes change of context or more for each selection in the union all the
>
A single switch since the entire SQL (i.e. all queries combined set) is sent.
>
is there a better way to do it?
>
It depends on. What you do with the data you are interviewing?
The best way is to use SQL instead of PL/SQL whenever possible. But since we do not know what everything you do has no way to help us. -
Hello Experts,
Please review the below excerpt as it errors with a PLS-00103: Encoountered synbol «END».
IF v_geospatial_coordinate_type = "None".
THEN
P_cursor OPEN;
LOOP
SEARCH p_cursor
LOOSE COLLECTION v_search_results_basic LIMIT 100;
BECAUSE me in 1.v_search_results_basic.count
WHEN the OUTPUT v_search_results_basic.count < 100;
END LOOP;
CLOSE P_cursor;
Thanks for the help and of course your professionalism.you missed "LOOP".
IF v_geospatial_coordinate_type = 'None' THEN OPEN p_cursor; LOOP FETCH p_cursor BULK COLLECT INTO v_search_results_basic LIMIT 100; FOR I in 1..v_search_results_basic.count LOOP --<--- EXIT WHEN v_search_results_basic.count < 100; END LOOP; CLOSE p_cursor;
-
How to get line numbers to COLLECT in BULK
Hello
I have a cursor loop where I insert a record into < HEADERS table >.
Inside this loop, I do
SELECT * COLLECT LOOSE lines_table
...
FORALL x IN lines_table. FIRST... lines_table. LAST
INSERT INTO < table > VALUES)
< sequence row id >. NEXTVAL,
< need to insert the number of the line here >
So I need to have the line number for heading 1,: 1, number of line: 2,...
For heading 2, I need to have the line number: 1, number of line: 2 and so on.
Any ideas?
Thank you
Anatoliy
I have line_number in my collection. But here's my problem: if I add rownum in the selection list, for example
SELECT FAH_DATA_STG_ID
BATCH_ID
..........
ROWNUM as line_number
LOOSE COLLECTION lines_table
Of
Well - it's confusing.
You say you "have line_number in my collection. But then, you ask, that if you add ROWNUM in the selection list he has no place to put it.
BOTH cannot be correct.
Your SCALAR type MUST HAVE an attribute for each value you want to include. If you must have an attribute for EACH column of the table (if you need all the columns) and then an attribute more to the line number.
Then, the SELECT list must have the SAME NUMBER of values.
Maybe you are looking for
-
Cannot disable new message sound in 31.3.0: prefs checkbox has no effect
After you install this update, I was surprised to hear a beep at each arrival of a new e-mail message. The related checkbox (General::Play sound) has no effect. I get the sound if the box is checked or unchecked. After you change the setting stop and
-
Where is FinderSyncAPIExtension
The last two times I turned on my iMac (27 ", late 2013; 10.11.3 bone), a window is open on the desktop with the question above" where is FinderSyncAPIExtension? The window has a comprehensive list of all applications on the computer (and includes ba
-
Upgradation of RAM in the model of 2110TU
Hello I bought HP Pavilion dv4-2110tu laptop. Posses IT core i3 and 4 GB of RAM. Now, I want to upgrade the RAM. I want another 4 GB of RAM, as well as the machine will have 8 GB of RAM that will solv my goal. My questions are these. 1. this laptop m
-
How to enter the IdeaCentre Q700 BIOS setting screen?
How to enter the IdeaCentre Q700 BIOS setting screen? Tried F1 and there is no setting in the BIOS. Thanks for any help!
-
OJ Pro 8000 A809n - printer lights up with LEDs indicating paper jam
OJ Pro 8000 A809n - equipped printer CONTINUE and the POWER of the lights. I press NEXT and it feeds a sheet, but top sheet passes through the print area and stops at halfway to the bottom of the sheet. I press CONTINUE and it ejects the sheet, but t