Using Arrays in SELECT BULK queries
Dear All,
Can we use arrays in the SELECT Bulk operations.
Example:
SELECT empno BULK COLLECT INTO v_empno FROM EMP WHERE deptno = v_deptno(m);
Is there any way we can simulate this example.
Appreciate your response on this one.
Thanks,
Madhu K.
Yes you can. See the example.
SQL> set serverout on
SQL> declare
2 TYPE varr_typ IS VARRAY(2) OF NUMBER;
3 my_varr varr_typ:=varr_typ(20) ;
4 TYPE rec_typ IS RECORD (fname EMPLOYEES.First_Name%TYPE,
5 lname EMPLOYEES.LAST_NAME%TYPE);
6 TYPE tmp_tbl IS TABLE OF rec_typ;
7 my_tbl tmp_tbl;
8 BEGIN
9 --my_varr(1):=20;
10 SELECT FIRST_NAME,LAST_NAME
11 BULK COLLECT INTO my_tbl
12 FROM EMPLOYEES
13 WHERE department_id=my_varr(1);
14
15 FOR i IN 1..my_tbl.COUNT LOOP
16 DBMS_OUTPUT.put_line(my_tbl(i).fname||' '||my_tbl(i).lname);
17 END LOOP;
18 END;
19 /
Michael Hartstein
Pat Fay
PL/SQL procedure successfully completed.
Similar Messages
-
I was wondering what the syntax is for using a forall with a array. I want to do something like below but this doesnt work correctly.
forall i in 1 .. p_array.COUNT
insert into test_object (attr_id, attr_1, attr_2)
values (p_array(i).attr_id,
p_array(i).attr_1,
p_array(i)).attr_2;
version 10g
Message was edited by:
user457357Not tested
declare
type v_array is table of emp%rowtype;
v_array1 v_array;
BEGIN
select * BULK COLLECT INTO v_array1
from emp;
forall x in v_array.FIRST..v_array.LAST
INSERT INTO table_name VALUES(x);
END;
/ G. -
Is there any way to use the Yahoo! Bulk folder as the Mail "Junk" folder?
I've been helping a few people with Yahoo! accounts and they'd like to use the Yahoo! "Bulk Mail" folder as their "Junk" folder so they don't have to select the messages in their Bulk folder in order to delete them with Apple Mail.
Unfortunately, I haven't found a way; you can tell Mail to use the Yahoo! Bulk Mail folder for Junk all day, but it never "takes."I have several Yahoo! accounts, as well, and have a similar issue. No solution for me.
-
How can i use index in select query.. facing problem with the select query.
Hi Friends,
I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
Here is the query:
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelat LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelatrprctr
WHERE rldnr = c_telstra_accounting
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
And rzzlstar in r_lstar
AND rpmax = c_max_period.
There are 5 indices present for Table ZTFTELAT.
Indices of ZTFTELAT:
Name Description
0 Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)
005 Profit (RCLNT,RPRCTR)
1 Ledger, company code, account (RLDNR,RBUKRS, RACCT)
2 Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)
3 Account, cost center (RACCT,RCNTR)
4 RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR
Z01 Activity Type, Account (RZZLSTAR,RACCT)
Z02 RYEAR-RBUKRS- RZZZBER-RLDNR
Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
Thanks in advance.Hi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
Assigning a value to an array cell populated [BULK]
Hi all,
I've got a problem in assigning a value to an array populated with BULK COLLECT INTO .
I can reproduce the problem with this
CREATE TABLE TEST_TABLE (
value1 NUMBER,
value2 NUMBER
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);
INSERT INTO test_table VALUES(1,1);And this is the PL/SQL anonymous block that gives me problems:
DECLARE
SUBTYPE t_rec IS TEST_TABLE%ROWTYPE;
TYPE records_table IS TABLE OF t_rec;
elist RECORDS_TABLE;
CURSOR table_cursor IS SELECT * FROM TEST_TABLE WHERE rownum <= 20;
BEGIN
OPEN table_cursor;
FETCH table_cursor BULK COLLECT INTO elist;
FOR j IN 1..elist.COUNT
LOOP
elist(j)(1) := elist(j)(1) +1;
END LOOP;
CLOSE table_cursor;
END; The error is
ORA-06550: line 13, column 7:
PLS-00308: this construct is not allowed as the origin of an assignment
ORA-06550: line 13, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:So it doesn't compile because of this line of code:
elist(j)(1) := elist(j)(1) +1;
Why doesn't it work?
If I try to do this, works perfectly:
DECLARE
TYPE v_num_table
IS
TABLE OF NUMBER;
TYPE v_2_num_table
IS
TABLE OF v_num_table;
v_nums V_2_NUM_TABLE := V_2_NUM_TABLE();
BEGIN
v_nums.EXTEND;
v_nums(1) := v_num_table();
v_nums(1).EXTEND;
v_nums(1)(1) := 1;
v_nums(1)(1) := v_nums(1)(1) +1;
dbms_output.put_line(v_nums(1)(1) );
END;Edited by: user10396517 on 2-mar-2012 2.35Variable "elist" is a collection of record, so you access an individual field of a given collection element by specifying the field name, not its position :
DECLARE
SUBTYPE t_rec IS TEST_TABLE%ROWTYPE;
TYPE records_table IS TABLE OF t_rec;
elist RECORDS_TABLE;
CURSOR table_cursor IS SELECT * FROM TEST_TABLE WHERE rownum <= 20;
BEGIN
OPEN table_cursor;
FETCH table_cursor BULK COLLECT INTO elist;
FOR j IN 1..elist.COUNT
LOOP
elist(j).value1 := elist(j).value1 + 1;
END LOOP;
CLOSE table_cursor;
END;Your second example is different as you're dealing with a collection of collections. -
How to use SQL functions in the queries
hey guys i wanna know how to use SQL functions in the queries is it possible or not .
Hi,
Wat exactly that set values are?
those from sql query?
How to use count():
The COUNT() function returns the number of rows that matches a specified criteria.
SQL COUNT(column_name) Syntax
The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
SELECT COUNT(column_name) FROM table_name
SQL COUNT(*) Syntax
The COUNT(*) function returns the number of records in a table:
SELECT COUNT(*) FROM table_name
SQL COUNT(DISTINCT column_name) Syntax
The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
SELECT COUNT(DISTINCT column_name) FROM table_name
The IN function helps reduce the need to use multiple OR conditions.
The syntax for the IN function is:
SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n); -
How to use table type in bulk collect
Hi experts,
How to use table type in bulk collect see the procedure used( oracle 10g)
and error is
PLS-00597: expression 'REQ_REC' in the INTO list is of wrong type
CREATE OR REPLACE PROCEDURE SAMPLE_SP IS
TYPE TYP_A AS OBJECT
( COLMN1 TABLE1.COLM1%TYPE,
COLMN2 TABLE1.COLM2%TYPE,
COLMN3 TABLE1.COLM3%TYPE
TYPE REC_A IS TABLE OF TYP_A;
REQ_REC A_REC;
CURSOR REQ_CUR IS SELECT COLM1,COLM2,COLM3 FROM TABLE1 WHERE <CONDITION>;
BEGIN
OPEN REQ_REC;
LOOP
EXIT WHEN REQ_REC%NOTFOUND;
FETCH REQ_REC BULK COLLECT INTO REQ_REC LIMIT 1000;
FOR I IN 1..REQ_REC.COUNT
LOOP
<insert statement>
END LOOP;
COMMIT;
END LOOP;
END SAMPLE_SP;
Many thanks,
Kalingaok but that is not an issue..
Hi experts,
How to use table type in bulk collect see the procedure used( oracle 10g)
and error is
PLS-00597: expression 'REQ_REC' in the INTO list is of wrong type
CREATE OR REPLACE PROCEDURE SAMPLE_SP IS
TYPE TYP_A AS OBJECT
( COLMN1 TABLE1.COLM1%TYPE,
COLMN2 TABLE1.COLM2%TYPE,
COLMN3 TABLE1.COLM3%TYPE
TYPE REC_A IS TABLE OF TYP_A;
REQ_REC A_REC;
CURSOR REQ_CUR IS SELECT COLM1,COLM2,COLM3 FROM TABLE1 WHERE <CONDITION>;
BEGIN
OPEN REQ_CUR;
LOOP
EXIT WHEN REQ_REC%NOTFOUND;
FETCH REQ_REC BULK COLLECT INTO REQ_REC LIMIT 1000;
FOR I IN 1..REQ_REC.COUNT
LOOP
<insert statement>
END LOOP;
COMMIT;
END LOOP;
END SAMPLE_SP;
Many thanks,
Kalinga
Message was edited by:
Kalinga -
How to use Array in Formcalc?
Please share syntax for using Array in Formcalc.
Hi,
FormCalc is a simple scripting language and does not support objects like arrays.
The only function that come close to an array in JavaScript is Choose(),
This first parameter selects the nth value of the following comma separated strings.
Choose(3, "String1", "String2", "String3", "String4")
returns String3 -
HOW to USE 'LONG RAW' in Bulk Insertion using OCI
Hi,
I need to do bulk insertion of LONG RAW data into a table using the OCI.
To the OCIBindByPos API what should I specify in the field size(value_sz). As different records can have different lenght for this LONG RAW data what value should I provide.
Thanks,
Tuhin
sword OCIBindByPos ( OCIStmt *stmtp,
OCIBind **bindpp,
OCIError *errhp,
ub4 position,
dvoid *valuep,
sb4 value_sz,
ub2 dty,
dvoid *indp,
ub2 *alenp,
ub2 *rcodep,
ub4 maxarr_len,
ub4 *curelep,
ub4 mode );ORA-00997: illegal use of LONG datatype
Cause: A value of datatype LONG was used in a function or in a DISTINCT, WHERE, CONNECT BY, GROUP BY, or ORDER BY clause. A LONG value can only be used in a SELECT clause.
Action: Remove the LONG value from the function or clause
Are you using the column anywhere else but in the SELECT? -
Hi,
Is it possible to do a kind of select bulk from PHP ?
In my case, when I retrieve lot of data from a table and display it, I use a basic select but I can see the page is loading gradually.
I think if I am using the equivalent of a select bulk it would load all in one way.
Does anyone has an idea or advice ?
Best regards.Yeah I am echoing each line it returns.
Even if I use prefetch 3000 it look like same !
$stmt_select = ociparse($connect, $query);
oci_set_prefetch($stmt_select, 3000);
oci_execute($stmt_select,OCI_DEFAULT);
while ($select = oci_fetch_array ($stmt_select, OCI_BOTH))
$remote_img = $select['REMOTE_IMG'];
$text = $select['TEXT'];
$count = $count + 1;
echo '<table>';
echo '<tr>';
echo '<td>';
echo '<img src="' . $remote_img . '" width="100">';
echo '</td>';
echo '<td>';
$desc = str_replace('<br>', '-',$text);
$desc = str_replace(' ', '-',$desc);
echo $text;
echo '</td>';
echo '</tr>';
echo '<table>';
} -
Is it possible to do select distinct queries with Kodo/JDO? I have a table
of with a county field and a state field. There are obviously many counties
for each state. I'd like to get a list of just the states using a select
distinct query. Do I have to use JDBC or one of the query extensions to do
this?Hi Abe
Can you show us the query you are executing that returns duplicateobjects?
String filter = " _measurements.contains(measurement) &&
measurement._labRef.startsWith(labRef)";
Query query = pm.newQuery(Sample.class, filter);
query.declareParameters("java.lang.String labRef");
query.declareVariables("SampleMeasurement measurement");
Collection samples = (Collection)query.execute("foo Name");
"Sample" contains a collection of "SampleMeasurement" objects in the field
"_measurements".
According to the log, the following SELECT statement is created:
SELECT t0.JDOID, t0.JDOCLASS, t0.JDOVERSION, t0.NAME0, ...
FROM kodo.SAMPLE t0
INNER JOIN kodo.SAMPL__MEASUREMENTS t1
ON t0.JDOID = t1.JDOID
INNER JOIN kodo.SAMPLEMEASUREMENT t2
ON t1.MEASUREMENTS_JDOID = t2.JDOID
WHERE (t2.LABREF LIKE ?)
[params=(String) foo Name%]
The query returns for every matching SampleMeasurement a Sample object.
These objects may be duplicates.
Best regards
-- Pat -
Can I use Array Binding with a ExecuteDataSet or ExecuteReader methods?
I want to use Array binding with selects. From the examples that I see so far it seems like everyone is showing the ExecuteNonQuery method. I wonder if I can use this functionality with a regular query that returns ref cursoros.
Andrzejwhat is the error you recieve?
-
I have a web page written with combination of Front Page and Java is included. I have 4 drop down boxes which work in sequence. select an item in the first, it then asks you to select in the second box, then 3rd then in the final 4th box. This was set up using arrays. My question is how can i put a hyperlink to the items in the last drop down box? I want the last selection to go to a URL. can you tell me what code i need to use and where to insert it? I assume it has to go into the array somewhere. Thanks, Tom
selection to go to a URL. can you tell me what code
i need to use and where to insert it? Not without you clarifying your question and showing the relevant bits of your code, and possibly not even then.
When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
I assume it
has to go into the array somewhere. I assume it doesn't, because code doesn't go into arrays. -
Using applet to select a part of an image and then save it
Hi ,
I want to use applet to select a part of an image and then save that particular selected part to a server. can anyone provide me a code for this. I have found codes on the sun site which help in uploading an image but I am having trouble in trying to select a part of the image.Sorry to get back to you so late, but I was away from my computer this afternoon.
I'm not sure just what you are after. I do see that you have positioned the tree on the labels. I went to the web site for the label company, and their instructions are not too helplful.
http://www.pixentral.com/show.php?picture=15sBkl9OZE9xSkHoLMxgwjTFv2VCg1
I changed the white portion of 1 label to black - - this can be any color. To do this use the magic wand tool, tolerance=10 worked for me, then go to Edit>fill selection. -
How to use a Web Template with queries from multiple BW Systems?
Hi all,
can anybody help me how to use a Web Template with queries (DATA PROVIDER)in it from multiple BW Systems?
Thanks in advance, best regards
FrankGreat! Thanks for the quick response.
Have you tried this for XMLA datasources created within the EP system also?
i.e use Web Analyzer to create a view from the XMLA source and use that view within WAD?
Thanks.
Maybe you are looking for
-
How can i look up a EJB residing in different machine from client side?
hai , How can i look up a EJB residing in different machine from client side? this is my code...........i don't know what should i use as Initial Context Factory...................i am using a sun appserver 8............ package com.parx.lms.lmsdeleg
-
Find my friends appl. shows my location as wrong approx. 100 km away and same adress that never been there before . There should be another apple user these adress. How will I fix problem ?
-
I am trying to build a computer for my sister for christmas. I have everything up and running, except the computer randomly crashes. There seems to be no rhyme or reason to it. I can't reproduce the problem on command, sometimes it works for hours
-
Hello, I never did this before but I want to configure an email adres (gmail one) and use the POP to recieve those emails in the SAP system and then process them. I found some tutorials etc but they all handle with SENDING emails and using SMTP. Wher
-
Error "Not all data could be changed in LC" when running DP macro
We are getting the error, "Not all data could be changed in LC" when running DP macros and we are not sure why. It seems to only happen when we are executing it via a Process Chain but not using the DP background processing scheduling. Does anyone kn