Bulk Collect and limit the rows
Hello Oracles,I feel a strange (at least to me) behavior with lines in BULK COLLECT and LIMIT.
For test purposes, I've written a procedure that uses a CURSOR, explicit AND implicit.
When I use the explicit CURSOR and the LOOP, I use BULK COLLECT and LIMIT lines.
I do not ROWNUM limit with my SELECT INTO. I know for a fact ROWNUM works very well since the last millennium.
When I look at the number of rows returned when I put the LIMIT, I get weird number of extractions...
I recover in a TABLE INDEX BY which is based on a TYPE of ENTRY.
Here are a few results with different LIMIT values for a small group of key PRIMARIES.
The figures below are the value of my_table . COUNTY
Any idea would be apreciated.
THX
. .
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 78 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 78 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 78 retrieves: 27
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. Retrieves LOOP IN BULK COLLECT LIMIT 78: 37
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. Excerpt from LOOP BULK COLLECT LIMIT 78: 47
*************************************************
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 100 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 100 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 100 retrieves: 83
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. LOOP IN BULK COLLECT LIMIT 100 retrieves: 93
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. LOOP IN BULK COLLECT LIMIT 100 retrieves: 93
*************************************************
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 140 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 140 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 140 retrieves: 43
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. LOOP IN BULK COLLECT LIMIT 140 retrieves: 53
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. LOOP IN BULK COLLECT LIMIT 140 retrieves: 33
*************************************************
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 183 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 183 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 183 retrieves: 0
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. LOOP IN BULK COLLECT LIMIT 183 retrieves: 10
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. LOOP IN BULK COLLECT LIMIT 183 retrieves: 44
*************************************************
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 200 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 200 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 200 retrieves: 183
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. LOOP IN BULK COLLECT LIMIT 200 retrieves: 193
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. LOOP IN BULK COLLECT LIMIT 200 retrieves: 193
*************************************************
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 600 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 600 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 600 retrieves: 183
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. LOOP IN BULK COLLECT LIMIT 600 retrieves: 193
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. LOOP IN BULK COLLECT LIMIT 600 retrieves: 593
*************************************************
Actual number of CURSOR EXPLICIT 470553 PK = 17
. LOOP IN BULK COLLECT LIMIT 593 retrieves: 17
.
Actual number of CURSOR EXPLICIT 100991 PK = 38
. LOOP IN BULK COLLECT LIMIT 593 retrieves: 38
.
Actual number of CURSOR EXPLICIT 100981 PK = 183
. LOOP IN BULK COLLECT LIMIT 593 retrieves: 183
.
Actual number of CURSOR EXPLICIT 101001 PK = 193
. LOOP IN BULK COLLECT LIMIT 593 retrieves: 193
.
Actual number of CURSOR EXPLICIT 101033 PK = 593
. LOOP IN BULK COLLECT LIMIT 593 retrieves: 0
PL/SQL procedure successfully completed.
SQL > spool off
I love a mystery, so I figured out how your code might look like:
SQL> create table t
2 as
3 select case n1
4 when 1 then 470553
5 when 2 then 100991
6 when 3 then 100981
7 when 4 then 101001
8 when 5 then 101033
9 end pk
10 from (select level n1 from dual connect by level <= 5)
11 , (select level n2 from dual connect by level <= 593)
12 where ( (n1 = 1 and n2 <= 17)
13 or (n1 = 2 and n2 <= 38)
14 or (n1 = 3 and n2 <= 183)
15 or (n1 = 4 and n2 <= 193)
16 or (n1 = 5 and n2 <= 593)
17 )
18 /
Tabel is aangemaakt.
SQL> declare
2 type ta is table of number;
3 a_limitsizes ta := ta(78,100,140,183,200,600,593);
4 a_pks ta := ta(470553,100991,100981,101001,101033);
5 a ta;
6 l_actualcount number;
7 cursor c(b number) is select pk from t where pk = b;
8 begin
9 for i in a_limitsizes.first .. a_limitsizes.last
10 loop
11 for j in a_pks.first .. a_pks.last
12 loop
13 l_actualcount := 0;
14 open c(a_pks(j));
15 loop
16 fetch c bulk collect into a limit a_limitsizes(i);
17 l_actualcount := l_actualcount + a.count;
18 exit when a.count != a_limitsizes(i);
19 end loop;
20 close c;
21 dbms_output.put_line('PK ' || a_pks(j) || ' EXPLICIT CURSOR Actual Count = ' || l_actualcount);
22 dbms_output.put_line('. LOOP BULK COLLECT LIMIT ' || a_limitsizes(i) || ' retrieves : ' || a.count);
23 dbms_output.new_line;
24 end loop;
25 dbms_output.put_line('*************************************************');
26 dbms_output.new_line;
27 end loop;
28 end;
29 /
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 78 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 78 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 78 retrieves : 27
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 78 retrieves : 37
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 78 retrieves : 47
*************************************************
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 100 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 100 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 100 retrieves : 83
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 100 retrieves : 93
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 100 retrieves : 93
*************************************************
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 140 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 140 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 140 retrieves : 43
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 140 retrieves : 53
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 140 retrieves : 33
*************************************************
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 183 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 183 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 183 retrieves : 0
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 183 retrieves : 10
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 183 retrieves : 44
*************************************************
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 200 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 200 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 200 retrieves : 183
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 200 retrieves : 193
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 200 retrieves : 193
*************************************************
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 600 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 600 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 600 retrieves : 183
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 600 retrieves : 193
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 600 retrieves : 593
*************************************************
PK 470553 EXPLICIT CURSOR Actual Count = 17
. LOOP BULK COLLECT LIMIT 593 retrieves : 17
PK 100991 EXPLICIT CURSOR Actual Count = 38
. LOOP BULK COLLECT LIMIT 593 retrieves : 38
PK 100981 EXPLICIT CURSOR Actual Count = 183
. LOOP BULK COLLECT LIMIT 593 retrieves : 183
PK 101001 EXPLICIT CURSOR Actual Count = 193
. LOOP BULK COLLECT LIMIT 593 retrieves : 193
PK 101033 EXPLICIT CURSOR Actual Count = 593
. LOOP BULK COLLECT LIMIT 593 retrieves : 0
*************************************************
PL/SQL-procedure is geslaagd.
Observation of Randolf was right: you are simply watching the last extraction of a series of extractions, which is the modulo / rest.
Example: If your cursor retrieves a total of 183 ranks with a maximum size of 100, then your loop steps through twice. The first single 100 lines, the second 83. You print only the last extraction and not the sum of all the extractions.
Kind regards
Rob.
Tags: Database
Similar Questions
-
Exception handlers in bulk collect and for all operations?
Hello world
My version of DB is
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
AMT for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
My question is, what are the possible exception handlers can add us in a bulk collect and for all operations?
When we use for all, we add except exception and sql % bulk_exceptions. But apart from that what can we add to bulk collect?
Kind regards
BS2012.
Save stores Exception all the exceptions that occur during in bulk in a collection of treatment and at the end of the most much treatment raises an exception. The SQL % BULK_EXCEPTIONS collection has all exceptions. It's the right way to handle the exception during treatment in bulk. And that's all you need. Don't know what else await you.
-
Bulk Collect and Millions of records.
Hey guys,.
I did experiences autour with big collect in GR 11, 2...
I have millioms of files with very large tables.
In fact, my question is this. How do you use bulk collect when you have millions of records?
Everytime I try to use it for bulk collect into, I have run out of memory.
So should I stick with the SQL engine when it comes to manipulate millions
folders? Is maninly bulk collect for insert, updates to use for applications?
Summer banging my head for awhile with it. Can a Pl/SQL pro if you please
Give me some advice on this?
In most cases SQL insert/update engine will end up more quickly then PL/SQL select + Insert/Update. Normally, you would use PL/SQL, if there is a complex logic that is based on calculations of several rows that can be easily made in SQL. If you must use BULK COLLECT many or / and wide lines, you can divide it into segments using LIMIT.
SY.
-
Doubt on bulk collect with LIMIT
Hello
I have a doubt on in bulk to collect, when did Commit
I have an example in PSOUG
http://psoug.org/reference/array_processing.html
If my table servers were 3 000 000 files, when do we commit? When I insert all records?CREATE TABLE servers2 AS SELECT * FROM servers WHERE 1=2; DECLARE CURSOR s_cur IS SELECT * FROM servers; TYPE fetch_array IS TABLE OF s_cur%ROWTYPE; s_array fetch_array; BEGIN OPEN s_cur; LOOP FETCH s_cur BULK COLLECT INTO s_array LIMIT 1000; FORALL i IN 1..s_array.COUNT INSERT INTO servers2 VALUES s_array(i); EXIT WHEN s_cur%NOTFOUND; END LOOP; CLOSE s_cur; COMMIT; END;
could crash redo log?
using 9.2.08muttleychess wrote:
If my table servers were 3 000 000 files, when do we commit?Commit point has nothing to do with how many rows treat you. It's purely commercial leads. Your code implements a commercial operation, right? So if you're getting into before any trancaction (from the commercial point of view) other sessions will be already see changes that are (from a business point of view) incomplete. In addition, what happens if rest of trancaction (from the commercial point of view) goes down?
SY.
-
Hello, I'm quite new to PLSQL and need some advice...
I have several procedures that work well and do what I want to do.
My question is, am I'm going in the right direction or would you all another way? If there were millions of records that would be the fastest way?
All comments/comments would be greatly appreciated.
Procedure 1:
declare
type membera is the table of the gym_members_payment_details.member_id%type;
payment type is the gym_members_payment_details.payment_plan%type table;
type date_payment_recieved is table of the gym_members_payment_details.date_payment_recieved%type;
v_member membera;
v_payment payment;
v_date_payment_recieved date_payment_recieved;
date of v_date_due;
cursor c1 is select member_id, payment_plan, gym_members_payment_details date_payment_recieved;
Start
Open c1;
collect the fetch c1 into bulk in v_member, v_payment, v_date_payment_recieved;
Close c1;
I'm in v_member.first... v_member. Last
loop
If v_payment (i) = "daily" then update gym_members_payment_details set date_payment_due = v_date_payment_recieved (i) where member_id = v_member (i);
elsif v_payment (i) is "weekly" then update gym_members_payment_details set date_payment_due = v_date_payment_recieved (i) + 7 where member_id = v_member (i);.
elsif v_payment (i) is "monthly" then update gym_members_payment_details set date_payment_due = v_date_payment_recieved (i) + 30 where member_id = v_member (i);.
end if;
end loop;
end;
Procedure 2
declare
Bench type is the gym_members_lifts.bench_kg%type table;
squat type is the gym_members_lifts.squat_kg%type table;
type of death is the gym_members_lifts.deadlift_kg%type table;
type membera is the table of the gym_members_lifts.member_id%type;
type bodyw is table of the gym_members_lifts.body_weight_kg%type;
V_bench bench;
v_squat squat;
v_dead dead;
v_body bodyw;
number of v_total;
number of v_ratio;
v_member membera;
cursor c1 is select bench_kg, squat_kg, deadlift_kg, member_id, gym_members_lifts body_weight_kg;
Start
/ * bulk collect * /.
Open c1;
collect the fetch c1 into loose in v_bench, v_squat, v_dead, v_member, v_body;
Close c1;
/ * Update gym_members elevators table with combined lifts and body weight to lift rates rounded to 2 places * /.
I'm in v_member.first... v_member. Last
loop
v_total: = v_bench (i) + v_squat (i) + v_dead (i);
Update gym_members_lifts set total_lift_kg = v_total where v_member (i) = member_id;
v_ratio: = round ((v_bench (i) + v_squat (i) + v_dead (i)) / v_body (i), 2);
Update gym_members_lifts set bodyweight_strength_ratio = v_ratio where v_member (i) = member_id;
end loop;
end;
Published by: 882839 on November 29, 2011 14:25882839 wrote:
My question is, am I'm heading in the right direction
It depends on the type of film you make. Your direction may work for a movie comedy or a disaster, perhaps.
or you would do any differently?
Completely different.
If there were millions of records that would be the fastest way?
The fastest way is to do the absolute minimum of work to achieve the desired results.
You do not have to shake the SQL data in a detour by the PL/SQL engine. Bulk processing is slow.
While processing bulk is faster than 'normal' treatment - but for one reason only. Reduction in switching between SQL and PL/SQL engines.
The cost of treatment in bulk increases PGA - using more private process memory (the most expensive type of memory of the server). More extraction in bulk, the PGA TOUR more is consumed. Very large bed can crash the Oracle db server to the risk of exhausting all the free server memory and give rise to serious swap space trashing.
And that's all. Treatment in bulk does not run the SQL cursor all faster. Treatment in bulk does not reduce the IO very expensive and slow. There is no that activate more lines have to be extracted from the SQL cursor by context switch and thus reduce the change of context.
In this regard, what is optimal? No change at all in context.
How is this achieved? No treatment in bulk. It is obtained by eliminating the need to change entirely in context. This means no PL/SQL. This means that SQL.
Optimize SQL. Minimize the PL/SQL.
Do not use the PL/SQL engine to do the things that the SQL engine is perfectly capable of doing.
Simplistic example in the sense of your first PL/SQL procedure:
SQL> create table foo( id number, payment varchar2(1), due date ); Table created. SQL> SQL> insert into foo select level, 'D', null from dual connect by level <= 5; 5 rows created. SQL> insert into foo select level+5, 'W', null from dual connect by level <= 5; 5 rows created. SQL> SQL> update foo 2 set due = ( 3 case 4 when payment = 'D' then trunc(sysdate+1) --// daily payment's due date calc 5 when payment = 'W' then trunc(sysdate+7) --// weekly payment's due date calc 6 end 7 ); 10 rows updated. SQL> SQL> select * from foo; ID P DUE ---------- - ------------------- 1 D 2011/12/01 00:00:00 2 D 2011/12/01 00:00:00 3 D 2011/12/01 00:00:00 4 D 2011/12/01 00:00:00 5 D 2011/12/01 00:00:00 6 W 2011/12/07 00:00:00 7 W 2011/12/07 00:00:00 8 W 2011/12/07 00:00:00 9 W 2011/12/07 00:00:00 10 W 2011/12/07 00:00:00 10 rows selected. SQL>
-
Bulk collect and type returns nothing
Hello
I have the following code:
This code returns PL/SQL procedure successfully completed.declare type view_my_type is table of admuser.my_view%rowtype index by pls_integer; --x admuser.my_view%rowtype; my_array view_my_type; cursor c1 is select * from admuser.my_view; s long; i number := 1; begin s := 'crate table '; open c1; loop fetch c1 bulk collect into my_array limit 1; --s := s ||' decode (tf.fin_dates_id, '||my_array(i).fin_dates_id||', sum(tf.act_work_cost), 0) '; s := my_array(i).fin_dates_id; exit when c1%notfound; end loop; close c1; dbms_output.put_line(s); exception when others then null; end;
but don't show me is not the variable "s".
Can you help me with this?
Thank youThere a quite a number of things not just here.
First of all, allow me to reproduce your situation:SQL> create table my_view 2 as 3 select 'hello' fin_dates_id from dual 4 / Table created. SQL> declare 2 type view_my_type is table of my_view%rowtype index by pls_integer; 3 my_array view_my_type; 4 cursor c1 is 5 select * 6 from my_view; 7 s long; 8 i number := 1; 9 begin 10 s := 'crate table '; 11 open c1; 12 loop 13 fetch c1 bulk collect into my_array limit 1; 14 s := my_array(i).fin_dates_id; 15 exit when c1%notfound; 16 end loop; 17 close c1; 18 dbms_output.put_line(s); 19 exception 20 when others then 21 null; 22 end; 23 / PL/SQL procedure successfully completed.
And I SERVEROUTPUT on. Your exception handler is notoriously wrong. It is said: If something goes wrong, we'll pretend it didn't happen. And that's exactly what happened here: something has gone wrong and you have chosen to not know about it.
We will remove the exception handler to see what went wrong:
SQL> declare 2 type view_my_type is table of my_view%rowtype index by pls_integer; 3 my_array view_my_type; 4 cursor c1 is 5 select * 6 from my_view; 7 s long; 8 i number := 1; 9 begin 10 s := 'crate table '; 11 open c1; 12 loop 13 fetch c1 bulk collect into my_array limit 1; 14 s := my_array(i).fin_dates_id; 15 exit when c1%notfound; 16 end loop; 17 close c1; 18 dbms_output.put_line(s); 19 end; 20 / declare * ERROR at line 1: ORA-01403: no data found ORA-06512: at line 14
A no-data-found, because you are referencing my_array (i), when I is null. Just move the OUTPUT when a line upwards as well as your code runs better:
SQL> declare 2 type view_my_type is table of my_view%rowtype index by pls_integer; 3 my_array view_my_type; 4 cursor c1 is 5 select * 6 from my_view; 7 s long; 8 i number := 1; 9 begin 10 s := 'crate table '; 11 open c1; 12 loop 13 fetch c1 bulk collect into my_array limit 1; 14 exit when c1%notfound; 15 s := my_array(i).fin_dates_id; 16 end loop; 17 close c1; 18 dbms_output.put_line(s); 19 end; 20 / hello PL/SQL procedure successfully completed.
Then next to fix things are:
-do not use the long data type Use a VARCHAR2 or a CLOB.
-' Cashier' should probably be 'create '.
-in bulk, treatment with limit 1. Now you have the worst of both sides: line by line, treatment and slightly more complex syntax
-Variable increment I
-Easier (and thus better) use a loop FORI hope this helps.
Kind regards
Rob. -
Bulk collect and cursors using rowtype
Hello
I'm trying just one big collect of a table and display one of the values.
It keeps giving me the error:
dbms_output.put_line ('f_viewed_rec: ' | f_viewed_rec.job_id (i));
*
ERROR on line 66:
ORA-06550: line 66, column 53:
PLS-00302: component 'JOB_ID' must be declared.
----
cursor f_viewed IS
Select job_id of the work;
type f_viewed_type is table of the f_viewed % rowtype;
f_viewed_rec f_viewed_type;
Start
Open f_viewed;
LOOP
F_viewed fetch bulk collect within the limit of 5000 f_viewed_rec;
--------
I'm in f_viewed_rec.first... f_viewed_rec. Last
LOOP
dbms_output.put_line ('f_viewed_rec: ' | f_viewed_rec.job_id (i));
END LOOP;
END LOOP;
end;
/
--------------------------
Any ideas? Thanks much for any help.
-JennyDifficulty
dbms_output.put_line('f_viewed_rec: '||f_viewed_rec.job_id(i));
TO
dbms_output.put_line('f_viewed_rec: '||f_viewed_rec(i).job_id);
Kind regards
Sayan M. -
Bulk collect fresh limit clause
Hey,.
There is little theoretical question about bulk collect.
Have searched a lot of books but could not get the right solution.
How do we calculate the value optimized for the fired limit bulk clause?
-Say we have 10 million records... What should be the optimized value of limit?
-We have 100 million documents... What should be the optimized value of limit?
My code woks strangely... I was wondering what would be the limit?Value optimized in the Limit clause is equal tohow amount of memory you can afford to consume in the PGA and then adjust the limit to be as close to that amount as possible.
Use of the below block to check that limit what value would be the most appropriate for your system, since it depends of your allocation of memory and CPU consumption.DECLARE PROCEDURE fetch_all_rows (limit_in IN PLS_INTEGER) IS CURSOR source_cur IS SELECT * FROM all_source; TYPE source_aat IS TABLE OF source_cur%ROWTYPE INDEX BY PLS_INTEGER; l_source source_aat; l_start PLS_INTEGER; l_end PLS_INTEGER; BEGIN DBMS_SESSION.free_unused_user_memory; show_pga_memory (limit_in || ' - BEFORE'); l_start := DBMS_UTILITY.get_cpu_time; OPEN source_cur; LOOP FETCH source_cur BULK COLLECT INTO l_source LIMIT limit_in; EXIT WHEN l_source.COUNT = 0; END LOOP; CLOSE source_cur; l_end := DBMS_UTILITY.get_cpu_time; DBMS_OUTPUT.put_line ( 'Elapsed CPU time for limit of ' || limit_in || ' = ' || TO_CHAR (l_end - l_start) ); show_pga_memory (limit_in || ' - AFTER'); END fetch_all_rows; BEGIN fetch_all_rows (1); fetch_all_rows (5); fetch_all_rows (25); fetch_all_rows (50); fetch_all_rows (75); fetch_all_rows (100); fetch_all_rows (1000); fetch_all_rows (10000); fetch_all_rows (100000); END;
-
code is: cursor here can fetch a large amount of data (22000 records). So I have to go with the limit clause. I use two foralls. This code snippet is correct with regard to the two foralls, exit and % bulk_rowcount sql statement? I have to use in production. Is there something that can break the code?
OPEN c1;
LOOP
C1 FETCH BULK COLLECT WITHIN the limits of the 100 id_array;
FORALL i IN id_array. FIRST... id_array. LAST
Update statement;
BECAUSE me IN id_array. FIRST... id_array. LAST
LOOP
v_cnt: = v_cnt + SQL % BULK_ROWCOUNT (i);
END LOOP;
FORALL i IN id_array. FIRST... id_array. LAST
Insert statement;
WHEN id_array EXIT. COUNT = 0;
END LOOP;
CLOSE c1;
In addition, how context switching works when we use the llimit clause?
without limit:
collection is completely filled. then prepares to all the DML statements and go to sql and exeutes one by one.
right?
tasted clause say limit = 100
100 indexes collection gets populated.then prepares all the DML statements for these 100 indices and go to the DTF sql and exeutes. And then back to pl/sql. fills the same 100 indices collection with 100 records and prepares the DML and goes to sql to run and returns to pl/sql and so on? Is this true?
right?large volume of data (22000 records)
This isn't a large volume of data.
In addition, how context switching works when we use the llimit clause?
You will find some good explanations here:
http://www.Oracle.com/technology/tech/pl_sql/PDF/doing_sql_from_plsql.PDF
-
How to limit the rows returned from the user role-based interactive reports
Hello
I'm a new Apex-PL/SQL Developer, looking for some recommendations on how to implement an interactive report to display different lines in your current application ROLE service.
For example let's say you have an application for orders and 2 different roles: superuser and sales-rep
Now, if super user connects to the application, it should be able to see all the rows in the orders table, however, if the user 'john' connects with the commercial list, he should see those orders assigned to him.
I don't think I can use "dynamic" sql and build my where clause on the fly if I choose an interactive report so I was looking around and came across the concept of a common function but it seems that some other people do this with collections of the APEX. Is there anyone with a recommendation for one to use? A few books I've read recommend putting most of the logic that you can on your database (easier to maintain in the long term) that's why I thought about pipep functions using, but I thought I would check with the experts first.
Thank you!If you are allowed to use an Enterprise Edition database and to apply these restrictions, through the entire application, or across multiple applications, then use of private virtual database (DPV), with the security attributes of PL/SQL Code to the initialization/cleanup APEX application to set and reset the settings in your application.
Should you not use EE, then you can roll your own VPD use parameterized views.
If the restriction is only required for this unique IR, then, simply use a union of two mutually exclusive predicates opportunities:
select ... from orders su where :app_role = 'super-user' union all select ... from orders rep where :app_role = 'sales-rep' and rep.salesman = :app_user
All of these approaches should outperform functions in pipeline, collections, or a user-defined function (which, in a predicate that is executed for each line, mudra stopped the large datasets because of context switching).
-
Limit the rows of the fact Table by using a table Dim - 10 g
Hello
I'm having some trouble trying to restrict the result to a fact table using a Dim picture (assume that the example below).
-----DIM A-------------------------------FACT B--------------
ID-Code - Id_Date - Id_Dim - value
1---ABCD---01-01-2011---1---10
2---XYZ---02-01-2011---2---20
3---RST---03-01-2011---1---30
----------------------------------04-01-2011-------3------------40
I want to show only the rows where Dim.Code = 'ABCD '. I know on the MDB, I choose the LTS of the fact table and on the content tab, on where clause insert: Dim.Id = 1, but I don't want to be limited by Dim.Id, I want to limit by Dim.Code and who cannot do this way.
What I did on the LTS of the fact table, on the tab general got the fact Table on the mapped tables and I added the table Dim doing a join internal between the fact Table and the Table Dim. This way when I go to the content tab, I can do: Dim.Code = "ABCD" because the tables are attached now.
Is it bad to do? Is there a better way to solve this problem?
Before ask you I can't do it directly on the table of the Sun because this chart Dim is used in other Tables of facts. Creates an alias for the Table Dim and limit there the way forward?
I hope that I was clear, thank youThe way you do it is correct. If you have only one or two measures, then you could also do it using logical columns with the filter function.
table of facts, for example:
value = (unfiltered, do not show in the layer close)
Value of ABCD = (filter (value using dim code = "ABCD"))Then you can expand this without having to create a table of facts for each variation:
value = (unfiltered, do not show in the layer close)
Value of ABCD = (filter (value using dim code = "ABCD"))
Value of XYZ = (filter (value using dim code = "XYZ"))
First value = (filter (value using dim code = "RST"))etc. Contrary to the statements of case, it pushes the return filter logic to the database (you get a where clause clause). Kind regards
Robert
-
Problem with BULK collect and variable of Table type
Hi all
I defined a record type and then set an index - by table of this record type and in bulk has collected the data as shown in the code below. All this was done in an anonymous block.
Then when I tried to set the record as an object type and not the above activities type, I got the below error:
ORA-06550: line 34, column 6:
PL/SQL: ORA-00947: not enough values
ORA-06550: line 31, column 4:
PL/SQL: SQL statement ignored
Could you help me get the result of the first scenario with record type defined as an object?
Here's the code for num_char_object_1/* Formatted on 2009/08/03 17:01 (Formatter Plus v4.8.8) */ DECLARE TYPE obj_attrib IS TABLE OF num_char_object_1 INDEX BY PLS_INTEGER; obj_var obj_attrib; TYPE num_char_record IS RECORD ( char_attrib VARCHAR2 (100), num_attrib NUMBER ); TYPE rec_attrib IS TABLE OF num_char_record INDEX BY PLS_INTEGER; rec_var rec_attrib; BEGIN SELECT first_name, employee_id BULK COLLECT INTO rec_var FROM employees WHERE ROWNUM <= 10; FOR iloop IN rec_var.FIRST .. rec_var.LAST LOOP DBMS_OUTPUT.put_line ( 'Loop.' || iloop || rec_var (iloop).char_attrib || '###' || rec_var (iloop).num_attrib ); END LOOP; SELECT first_name, employee_id BULK COLLECT INTO obj_var FROM employees WHERE ROWNUM <= 10; END;
CREATE OR REPLACE TYPE NUM_CHAR_OBJECt_1 IS OBJECT ( char_attrib VARCHAR2 (100), num_attrib NUMBER );
Welcome to the forum!
You should be collecting objects in bulk, something like
SELECT NUM_CHAR_OBJECt_1 (first_name, employee_id) BULK COLLECT INTO obj_var FROM emp WHERE ROWNUM <= 10;
-
How to open a port and limit the range of addresses that use it on PIX 515?
I have a Pix 515 v6.3 and a new piece of software that I'm getting soon need aura 5080 open port for incoming & outgoing HTTP traffic. The server will be in my DMZ to 10.0.0.1
I would like to restrict inbound access to this port so that it can be used in 4 specific IP adderess foreign xxx.xxx.xxx.24 through xxx.xxx.xxx.27 and also, if possible, limit the outbound destination using this port to a single specific foreign IP address xxx.xxx.xxx.30.
Could you please tell me the best way to do it.
Thank you in advance for a relative novice to PIX.
PIX (config) # access list acl-outside permit tcp host xxx.xxx.xxx.24 host MyWWWPublicIP eq 5080
PIX (config) # access list acl-outside permit tcp host xxx.xxx.xxx.25 host MyWWWPublicIP eq 5080
PIX (config) # access list acl-outside permit tcp host MyWWWPublicIP eq xxx.xxx.xxx.26 host 5080
PIX (config) # access list acl-outside permit tcp host MyWWWPublicIP eq xxx.xxx.xxx.27 host 5080
PIX (config) # access - group acl-outside in interface outside
PIX (config) # access list acl - dmx permit tcp host 10.0.0.1 xxx.xxx.xxx.30 eq 5080
PIX (config) # access - group acl - dmz dmz interface
static (inside, outside) MyWWWPublicIP 10.0.0.1 netmask 255.255.255.255 0 0
See also:
PIX 500 series firewall
http://www.Cisco.com/pcgi-bin/support/browse/psp_view.pl?p=hardware:PIX & s = Software_Configuration
Configuration of the PIX Firewall with access to the Mail Server on the DMZ network
sincerely
Patrick
-
Limit the rows returned from a sql prompt of dashboard
Hello
I use the following sql in the dash prompt to generate a list of values:
SELECT LEFT (MONTHNAME ("begins and ends in days". (("" Start date "), 3) | » -'|| RIGHT (CAST (YEAR ("begins and ends in days". ((("" Start date ") AS VARCHAR (4)), 2) FROM the"metric"where"begins and ends in days. "" Start date "< = TIMESTAMPADD(SQL_TSI_MONTH, 1,current_date) ORDER BY 'Start and End Days '. "' Start date ' DESC
which gives me an output like MAY-13,APR-13,MAR-13,FEB-13,JAN-13,DEC-12...;
Is there a way to limit the release until FEB - 13...
Thank you
SunnyUse this
where ' start and end days '. " Start date.<=TIMESTAMPADD(SQL_TSI_MONTH,>=TIMESTAMPADD(SQL_TSI_MONTH,>
and "start and end days '." Start date "> = TIMESTAMPADD (SQL_TSI_MONTH,-2, current_date)"Check if help
-
Access table in the arraycollection collection and add the item at the end of the table
for "login_user":"XXX"},i); //mess2=sess_MessArr[i2]; //mess1=dispArray[i2].fwchat_message //searchArray(mess2);} (var i:int = 0; i< dispArray.length; ++i){ dispArray[i]. dispArray.addItemAt({
I have this code to try to access the values in the table in the arraycollection collection, but that's not it actually creates a value at the end of the arraycollection collection. can someone tell me what im doing wrong I basically want retransmits the individual tables in the arraycollection collection and add Login_userSo, I guess your ArrayCollection collection holds an array of objects, as follows:
public var myAC:ArrayCollection = new ArrayCollection([{first:"bob",last:"smith"},{first:"jim",last:"jones"},{first:"mary",last:"allen"}]);
And you try to add a new property of login_user to each of them, right?
for each (var obj:Object in myAC) { obj.login_user = obj.first + "83"; }
Each person would be firstly, properties last and login_user. In my example above, all the login_user would set their name + number 83, so adjust you accordingly for your application.
It is the ease (for each rock for this situation). However, if you want to paste the iterative approach, you have published, you can try this:
for (var i:int = 0; i < myAC.length; i++) { myAC.getItemAt(i).login_user = myAC.getItemAt(i).first + "83"; }
I think that the for each syntax is clearer, but anyway works the way I think you want.
Maybe you are looking for
-
Why doesn't 'request site Office' work?
Galaxy S3 with CSpire. requesting office site redirects me to site attach data from CSpire. I wish that it worked. I have to use another browser to view a desktop site.
-
Install now, where the hell is my printer code? And I can use my mobile phone number to set up my fax machine or do I need a landline?
-
RefNum Slide 'Visible '.
I have a Refnum to a slide (which is passed to the Sub - VI). The slide is on the Panel of the parent. I spent the Refnum zipper to the Subvi using 'Static Reference of VI' and 'Invoke node with Val.Set Ctrl', the problem is that the slide is visib
-
We are middle bussiness of size in support of 400 machines over 20 locations. 25% of these machines are infected with malware of high-end (BIOS rootkits). Which product is the best to help us clean up these machines? What is the best method to use? P
-
I just bought 564 cartridges and they seem to have no window of ink on the bottom of the cartridge and the machine that said on the fold small following "the ink cartridge seems to be missing or damaged. Refer to printer documentation ". The manual o