A different RETURN clause in FUNCTION
I am using Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production.
Hi Techie's,
I am having a table called DEV and trying to fetch all the records from a column called no from the same table. I know that i can do with the help of SYS_REFCURSOR. But I just tried to do something different here. When i compiled the function, it got created. But when i tried to execute, it throws some error.
I dont know what happens here between compilation and execution. Can someone give me some ideas? can we make this function to work? Correct me if i am understanding wrong.
CREATE OR REPLACE FUNCTION s_fn
RETURN dev%ROWTYPE
IS
l_d dev%ROWTYPE;
BEGIN
SELECT * INTO l_d FROM dev;
RETURN l_d;
END;
SELECT s_fn FROM DUALThanks
Ram
Your function is only expecting a single row to be returned from the SELECT statement, so if there's more than one row you'll get an error.
You need a pipeline function with a loop to achieve what you want. e.g.
SQL> CREATE OR REPLACE TYPE num_descript AS OBJECT(num number, descript varchar2(30))
2 /
Type created.
SQL>
SQL> CREATE OR REPLACE TYPE tbl_num_descript AS TABLE OF num_descript
2 /
Type created.
SQL>
SQL>
SQL> CREATE OR REPLACE PACKAGE reftest AS
2 FUNCTION pipedata(p_choice number) RETURN tbl_num_descript PIPELINED;
3 END;
4 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY reftest AS
2 FUNCTION pipedata(p_choice number) RETURN tbl_num_descript PIPELINED IS
3 v_obj num_descript := num_descript(NULL,NULL);
4 v_rc sys_refcursor;
5 BEGIN
6 IF p_choice = 1 THEN
7 OPEN v_rc FOR SELECT empno as num, ename as descript FROM emp;
8 ELSIF p_choice = 2 THEN
9 OPEN v_rc FOR SELECT deptno as num, dname as descript FROM dept;
10 END IF;
11 LOOP
12 FETCH v_rc INTO v_obj.num, v_obj.descript;
13 EXIT WHEN v_rc%NOTFOUND;
14 PIPE ROW(v_obj);
15 END LOOP;
16 CLOSE v_rc;
17 RETURN;
18 END;
19 END;
20 /
Package body created.
SQL> select * from table(reftest.pipedata(1));
NUM DESCRIPT
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SQL> select * from table(reftest.pipedata(2));
NUM DESCRIPT
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
SQL>
Similar Messages
-
What is the role of the RETURN clause in a pipelined function?
I wrote several pipelined functions and they work just fine without the return clause. However in the oracle's documentation there are returns in the pipelined functions:
CREATE FUNCTION StockPivot(p refcur_pkg.refcur_t) RETURN TickerTypeSet
PIPELINED IS
out_rec TickerType := TickerType(NULL,NULL,NULL);
in_rec p%ROWTYPE;
BEGIN
LOOP
FETCH p INTO in_rec;
EXIT WHEN p%NOTFOUND;
-- first row
out_rec.ticker := in_rec.Ticker;
out_rec.PriceType := 'O';
out_rec.price := in_rec.OpenPrice;
PIPE ROW(out_rec);
-- second row
out_rec.PriceType := 'C';
out_rec.Price := in_rec.ClosePrice;
PIPE ROW(out_rec);
END LOOP;
CLOSE p;
RETURN;
END;
/http://docs.oracle.com/cd/E11882_01/appdev.112/e10765/pipe_paral_tbl.htm#CHDJEGHC
Moreover, at least in PL/SQL developer I recieve hints that my pipelined functions return no values, though as I said the functions work smoothly. So is there a need in the return clause in pipelined functions or it is redundant?
My oracle version is 11.2.0.2.0As already mentioned, in later versions of the database it doesn't appear to be necessary, however, it IS good programming practice (and necessary in non-pipelined functions) to always ensure a function has a RETURN statement in it. It could be a 'side effect' (read that as bug if you like) that it doesn't appear to be necessary, so you would be best to ensure you DO include a RETURN statement, as documented.
-
Two methods with same name but different return type?
Can I have two methods with same name but different return type in Java? I used to do this in C++ (method overloading or function overloading)
Here is my code:
import java.io.*;
public class Test{
public static void main(String ar[]){
try{
//I give an invalid file name to throw IO error.
File file = new File("c:/invalid file name becasue of spaces");
FileWriter writer = new FileWriter(file ,true);
writer.write("Test");
writer.close();
} catch (IOException IOe){
System.out.println("Failure");
//call first method - displays stack trace on screen
showerr(NPe);
//call second method - returns stack trace as string
String msg = showerr(NPe);
System.out.println(msg);
} // end of main
public static void showerr(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
try{
pw.close();
sw.close();
catch (IOException IOe){
IOe.printStackTrace();
String stackTrace = sw.toString();
System.out.println("Null Ptr\n" + stackTrace );
}//end of first showerr
public static String showerr(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
try{
pw.close();
sw.close();
catch (IOException IOe){
IOe.printStackTrace();
return sw.toString();
}//end of second showerr
} // end of class
[\code]Overloading is when you have multiple methods that have the same name and the same return type but take different parameters. See example
public class Overloader {
public String buildError(Exception e){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( e.getClass().getName() )
.append( " : " )
.append( e.getMessage() ) ;
return buffer.toString() ;
public String buildError(String msg){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( msg ) ;
return buffer.toString() ;
public String buildErrors(int errCount){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( "There have been " )
.append( errCount )
.append( " errors encountered.") ;
return buffer.toString() ;
}Make sense ???
Regards, -
Multiple returns in a function
Hello,
I have a requirement where price for a product at a store is calculated and returned in a function.
1. First check if there is any 'advertised price' and if there is any, return it.
2. Check if there is any 'every day low price' and if there is any, return it.
3. If both above conditions doesn't exist, then get it straight from another table.
Conditions to check if 1 or 2 exists are different. How can I control the logic to go to 2 if 1 doesn't exist? I tried with separate begin end blocks. But, using this, when condition 1 is not satisfied, it is directly going to exceptions .. without trying for 2. Thanks,Thanks for all the responses.
I was wondering if this design pattern is any better. Can you suggest? Thanks,
BEGIN
v_sql := condition 1
execute immediate v_sql;
EXCEPTION
WHEN NO DATA FOUND THEN
BEGIN
v_sql := condition 2
execute immediate v_sql;
EXCEPTION
WHEN NO DATA FOUND THEN
BEGIN
v_sql := condition 3
execute immediate v_sql;
EXCEPTION
WHEN OTHERS THEN
throw error
END --condition3
END --condition 2
END --condition 1 -
I have a table that has a PK value that is generated by a sequence that fetches sys_guid() for the value via an insert trigger.
How can i insert a record and get the pk value that was generated in one statement?
I know about the RETURNING clause and how it works. There are lots of examples out on google about using the RETURNING clause in a PL/SQL block.
My problem is that i am not writing a stored proc or function. I'm just executing SQL through a client (Aqua). So i don't have variables and bindings or anything like that.
What i want is to write something like the following:
INSERT INTO CONTACTS.TBLPEOPLE(PPLKEEPCONFIDENTIAL, PPLNAMELAST, PPLNAMEFIRST, PPLNAMEPREFIX, PPLNAMEMIDDLE, PPLNAMESUFFIX, PPLNAMEPREFERRED, PPLACTIVE, ADTUSERID, ADTDATELASTUPDATE)
VALUES('1', 'Doe', 'John', 'Mr', 'Q', '', '', '1', 'kg', SYSDATE)
RETURN PPLGUID
and for the result to be - 1 record inserted, here is the PPLGUID that was generated - '12CD-23FBBD-23222'
Can this be done?My problem is that i am not writing a stored proc or functionYou don't have to. Can't you just wrap the INSERT/RETURNING into an anonymous pl/sql block?
SQL> create sequence t_seq start with 42;
Sequence created.
SQL> declare
2 l_seq number;
3 begin
4 insert into t values (t_seq.nextval)
5 returning n into l_seq;
6 dbms_output.put_line('generated ' || l_seq);
7 end;
8 /
generated 42
PL/SQL procedure successfully completed.Edited by: SomeoneElse on Jul 30, 2009 12:27 PM
(working example) -
How to get the values returned by a function in a drop down?
Hi All,
Can anyone please help in getting the values returned by a function into a drop down? I have a java class file where in i have written a function called getWeeks() which give all the week dates and i want to display these week dates in a drop down box in a JSP page.
Please help me in this regard.
Thanks in Advance!!
Lakshman.Hi Lakshman,
the following code can help you do what you want :
<hbj:dropdownListBox id="calendar" tooltip="Calendar" selection="<%= selected %>">
<%
String[] weeks = myObjectBean.getWeeks();
for (int i = 0; i < weeks.length; i++) {
%>
<hbj:listBoxItem key="<%= i %>" value="<%= weeks<i> %>"/>
<%
%>
</hbj: dropdownListBox>
The <%= selected %> snippet allows you to pre-select one of the options (provided that the variable 'selected' is equal to one of the listBoxItem keys).
You can also add onSelect to the tag (e.g. = "setSelectedItem"). It corresponds to a method in the corresponding JSPDynPage class. This means that when you select another item in the dropdown list, the method in your Java class is performed (allowing you to save the selected value and performing actions with it)
I hope this helped you enough,
kind regards,
Frederic
Edited seven times by: Frederic Taes on Nov 5, 2008 11:24 AM -> the onSelect element was in the hbj tag and in the text with "='setSelectedItem'" next to it and when I tried to post my message, I got a 501 error all the time ! Seems like a SDN bug to me ... -
How can I remove iTunes 11 and return to a functional version of iTunes?
So I was really stupid and updated my perfectly operational version of iTunes to version 11. After discovering that version 11 is almost totally non-functional (missing a number of useful functions that someone decided were too helpful I guess), I want to delete this horrid example of software non-functionality and return to the last functional version (iTunes 10). Please tell me there's a way to remove this software wart and return to a functional iTunes.
I found the following way to return to 10.7. I moved the following directories and files to the desktop before I deleted iTunes 11:
Album Artwork (folder)
iTunes Media (folder)
Previous iTunes Libraries (folder)
The following file is found in the Previous iTunes Libraries:
iTunes Library 2012-11-29.itl (the date on your file will vary depending on when you decided to add version 11)
The following are files found in the iTunes directory
iTunes Library Genus.itdb
iTunes Library Extras.itdb
Once you have copied these files to your desktop, you have to remove iTunes 11. I used the uninstall option in CleanMyMac.
I used this explanation to return to iTunes 10.7:
Replace the iTunes 11 application with iTunes 10.7
https://discussions.apple.com/message/20431349
iTunes 10.7 for OS X http://appldnld.apple.com/iTunes10/041-7195.20120912.d3uzQ/iTunes10.7.dmg
You will have to rescue your old iTunes library from your Previous Libraries folder and rename it iTunes Library.itl because a newer version of iTunes irreversibly updates your library file. See:
https://discussions.apple.com/mesage/20401436 - turingtest2 11/2012 post on rebuilding empty/corrupt library after upgrade/crash from previous iTunes library file.
iTunes: How to re-create your iTunes library and playlists - http://support.apple.com/kb/ht1451
Other issues:
https://discussions.apple.com/message/20432309 - solution to mobile devices saying they need to be restored after downgrading
Once you have reinstalled 10.7, put the files and folders you copied to the desktop back into iTunes overwriting the new files that were created during the install. Restart iTunes and you should see iTunes start to reinstall all the missing files. This doesn't seem to recreate the playlists but I can fix that problem myself.
So far, it seems to be working. YMMV and I'm not recommending you try this, I'm just saying that it's worked for me. -
RETURN Clause in IF...ELSE Condition in PL/SQL Block
Hi
Could you please explain me the importance of a RETURN Clause in IF..ELSE Condition in PL/SQL Block with
an example.
Regards
Nakul.VHi,
RETURN clause permits get out of the block. For more information you can see [Using the RETURN Statement|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/subprograms.htm#sthref1683]
SET SERVEROUTPUT ON
BEGIN
IF 1 = 1 THEN
dbms_output.put_line('Before return');
RETURN;
ELSE
dbms_output.put_line('Else');
END IF;
dbms_output.put_line('After if');
END;
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> BEGIN
2 IF 1 = 1 THEN
3 dbms_output.put_line('Before return');
4 RETURN;
5 ELSE
6 dbms_output.put_line('Else');
7 END IF;
8 dbms_output.put_line('After if');
9 END;
10 /
Before return
PL/SQL procedure successfully completed
SQL> Regards,
Edited by: Walter Fernández on Dec 12, 2008 9:41 AM - Adding output
Edited by: Walter Fernández on Dec 12, 2008 9:43 AM - Adding URL... -
Error in RETURNING clause in INSERT.....SELECT query
Hi Friends
I am having an error: "SQL stmt not properly ended" when i run the below code.
Cant i fetch multiple values from the returning clause into a collection variable??
insert into consumption__C
(SITECODE, SALESORG, PRODFAM,CAMPCODE, CYEAR, MDATE, SYSENV, MTYPE, ACCOUNT__C, SUPPLIER__C,
PRODUCT_PER_UNIT__C, PRODUCT__C, UNIT__C, AMOUNT_Y__C, VOLUME_Y__C, CURRENCY__C,SUPPLYMODE__C)
select ' ' Sitecode,
' ' Salesorg,
' ' Prodfam,
' ' campcode,
' ' cyear,
pcurr_mig MDATE,
psysenv SYSENV,
'NSet' MTYPE,
c.sitecode Account__c,
' ' supplier__c,
' ' Product_per_unit__c,
c.material Product__c,
' ' unit__c,
c.Amount Amount_y__c,
' ' Volume__c,
'Euro' Currency__c,
' ' Supply_Mode__c
from load_sales_customer_site c returning c.customer_code bulk collect INTO temp;
Kindly guide...... what is the problem!!
Thanks in advancenice idea, but you can't use returning into with
insert as select:
SQL> select * from v$version;
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
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table exm(id primary key) as select object_id from all_objects
2 where rownum <=100;
Table created.
SQL> declare
2 type num_tbl is table of number;
3 ll_num_tbl num_tbl;
4 begin
5 insert into exm(id)
6 (select object_id * 100 from all_objects where rownum
7 <=100) returning id into ll_num_tbl;
8 end;
9 /
<=100) returning id into ll_num_tbl;
ERROR at line 7:
ORA-06550: line 7, column 9:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 5, column 2:
PL/SQL: SQL Statement ignoredAmiel -
Returning clause in MERGE statement
Hi ,
I'm using Oracle 10g Version
I tried the below code using UPDATE with Returning Clause & MERGE with Returning Clause .
I found NO errors while working with UPDATE statement . The following is the code with UPDATE statement
DECLARE
TYPE empno_list IS TABLE OF emp.empno%TYPE;
vempno_list empno_list;
BEGIN
UPDATE emp
SET comm = 11
WHERE deptno IN (SELECT deptno FROM dept)
RETURNING empno
BULK COLLECT INTO vempno_list;
FOR i IN vempno_list.FIRST .. vempno_list.LAST
LOOP
DBMS_OUTPUT.put_line ('Values of EMP ' || vempno_list (i));
END LOOP;
END;
But getting the error PL/SQL: ORA-00933: SQL command not properly ended when working with MERGE Statement
declare
type empno_list is table of emp.empno%type;
vempno_list empno_list;
begin
merge into emp tgt
using dept src
on (src.deptno =tgt.deptno)
when matched then
update set tgt.comm=12
returning tgt.empno bulk collect into vempno_list ;
for i in vempno_list.first .. vempno_list.last loop
dbms_output.put_line('Values of EMP '||vempno_list(i) ) ;
end loop;
end;
Please suggest meProbably because the RETURNING INTO clause doesn't belong to MERGE statement. It's available only for INSERT, UPDATE and DELETE. Here is the quote from Oracle Documentation:
The static RETURNING INTO clause belongs to a DELETE, INSERT, or UPDATE statement. The dynamic RETURNING INTO clause belongs to an EXECUTEIMMEDIATE statement.
And here's the link.
RETURNING INTO Clause
Hope it helps.
Ishan -
Using RETURNING clause with Execute Immediate
I wrote a query to update a table and return the column in to a nested table type variable using returning clause but its not working I am getting error like
ORA-06550: line 66, column 22:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 66, column 4:
PL/SQL: Statement ignored
I am getting error in following part of my query
|| 'RETURNING if_row_status bulk collect INTO '
|| v_if_row_status;
v_if_row_status is defined as -
TYPE v_count IS TABLE OF varchar2(50) INDEX BY BINARY_INTEGER;
v_if_row_status v_count;I am trying to update a table for diffrent column if they are null and want no of column updated for each column.
I wrote following query but I am not getting the correct output.
UPDATE
Temp_Bulk_Col_POC
SET if_row_status = 'VALIDATED',
if_row_processed_date = sysdate,
if_row_error_msg =
CASE
WHEN record_type IS NULL
THEN 'RECORD_TYPE is a required column and cannot be NULL'
WHEN source_system IS NULL
THEN 'SOURCE_SYSTEM is a required column and cannot be NULL'
WHEN record_company IS NULL
THEN 'RECORD_COMPANY is a required column and cannot be NULL'
WHEN record_system IS NULL
THEN 'RECORD_SYSTEM is a required column and cannot be NULL'
WHEN txn_flag IS NULL
THEN 'TXN_FLAG is a required column and cannot be NULL'
WHEN create_date IS NULL
THEN 'CREATE_DATE is a required column and cannot be NULL'
WHEN UPDATE_date IS NULL
THEN 'UPDATE_DATE is a required column and cannot be NULL'
WHEN source_customer_id IS NULL
THEN 'SOURCE_CUSTOMER_ID is a required column and cannot be NULL'
WHEN source_product_id IS NULL
THEN 'SOURCE_PRODUCT_ID is a required column and cannot be NULL'
WHEN az_product_id IS NULL
THEN 'AZ_PRODUCT_ID is a required column and cannot be NULL'
WHEN decile IS NULL
THEN 'DECILE is a required column and cannot be NULL'
END
WHERE if_row_status IS NULL
AND (record_type IS NULL
OR source_system IS NULL
OR record_company IS NULL
OR record_system IS NULL
OR txn_flag IS NULL
OR create_date IS NULL
OR UPDATE_date IS NULL
OR source_customer_id IS NULL
OR source_product_id IS NULL
OR az_product_id IS NULL
OR decile IS NULL)
RETURNING if_row_status,record_type,source_system,record_company,record_system,
txn_flag,create_date,UPDATE_date,source_customer_id,source_product_id,az_product_id,
decile
BULK COLLECT INTO
v_if_row_status,v_record_type,v_source_system,
v_record_company,v_record_system,v_txn_flag,v_create_date,v_UPDATE_date,
v_source_customer_id,v_source_product_id,v_az_product_id,v_decile;
its showing same number for all the column.
how I can collect based on the coulmn updated -
Hi All,
I was trying to use RETURNING CLAUSE into pl/sql process but it gives error as :-
"1 error has occurred
* ORA-06550: line 12, column 13: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 6, column 3: PL/SQL: SQL Statement ignored"
Pl/sql process contains code as below:-
DECLARE
vID VARCHAR2(20);
BEGIN
INSERT INTO STUDENT_INFORMATION (DOB, AGE, OTHER_DATE, OTHER_AGE)
SELECT TO_DATE(C1_C002, 'MM/DD/YYYY'), C1_C003, TO_DATE(C1_C004, 'MM/DD/YYYY'), C1_C005
FROM (SELECT C1.C002 C1_C002, C1.C003 C1_C003, C1.C004 C1_C004, C1.C005 C1_C005
FROM APEX_COLLECTIONS C1
WHERE C1.COLLECTION_NAME = 'INFORMATION'
AND C1.SEQ_ID = 1)
RETURNING ID INTO vID; // IF I REMOVE THIS LINE & AND THIS INSERT STATEMENT WITH SEMICOLON(;) IN THE ABOVE LINE THE CODE WORKS FINE
// BUT THAN THE I'M GETTING ERROR WITH THE NEXT INSERT STATEMENT
INSERT INTO STUDENT_INFORMATION_GRADE (ID, GRADE_DATE, GRADE_AGE)
SELECT vID, TO_DATE(C2_C002, 'MM/DD/YYYY'), C2_C003
FROM (SELECT C2.C002 C2_C002, C2.C003 C2_C003
FROM APEX_COLLECTIONS C2, APEX_COLLECTIONS C1
WHERE C2.COLLECTION_NAME = 'GRADE'
AND C1.COLLECTION_NAME = 'INFORMATION'
AND C1.SEQ_ID = C2.SEQ_ID
AND C1.SEQ_ID = 1);
INSERT INTO STUDENT_INFORMATION_RESULT (ID, FINAL_RESULT)
SELECT vID, C3_C002
FROM (SELECT C3.C002 C3_C002
FROM APEX_COLLECTIONS C3, APEX_COLLECTIONS C1
WHERE C3.COLLECTION_NAME = 'RESULT'
AND C1.COLLECTION_NAME = 'INFORMATION'
AND C1.SEQ_ID = C3.SEQ_ID
AND C1.SEQ_ID = 1);
END;
I have trying RETURNING CLAUSE with other pl/sql process something like this :-
DECLARE
vID VARCHAR2(20;
BEGIN
INSERT INTO ..... ()
VALUES ()
RETURNING ID INTO vID;
INSERT INTO ... (ID, ....)
VALUES (vID, ..........)
END;
the above code works well with no errors, but when I'm using RETURNING CLAUSE with COLLECTIONS it gives me error.
Can anybody help me out?
Thanks
DeepDeep:
You can perform the inserts in a cursor loop as followsfor x in (SELECT C1.C002 C1_C002, C1.C003 C1_C003, C1.C004 C1_C004, C1.C005 C1_C005
FROM APEX_COLLECTIONS C1
WHERE C1.COLLECTION_NAME = 'INFORMATION'
AND C1.SEQ_ID = 1)
loop
INSERT INTO STUDENT_INFORMATION (DOB, AGE, OTHER_DATE, OTHER_AGE)
values ( TO_DATE(x.C1_C002, 'MM/DD/YYYY'),x.C1_C003, TO_DATE(x.C1_C004, 'MM/DD/YYYY'),x.C1_C005)
RETURNING ID INTO vID;
end loop;Varad -
Insert returning clause in Batch operation
I believe "insert returning" clause is not allowed in JDBC Batch operation, Is there any alternative way to achieve the same?
version: 10g release 2.
My requierment:
1. I would like to know the inserted value(sequence) after insert.
2. It is kind of mass upload, so looking at Batch operation.
Thanks,
Ravuthakumar2. It is kind of mass upload, so looking at Batch operation.That is not possible AFAIK.I'm pretty sure you could accomplish it with a callable statement that's passed a(some) collection(s) of values that are inserted en masse using an anonymous block something like this (compiled by eye) which will accumulate the returned value(s) into a(other) collection(s).
DECLARE
in_collection_1 some_collection_type := ?;
in_collection_n some_collection_type := ?;
out_collection_1 some_collection_type;
out_collection_n some_collection_type;
BEGIN
FORALL ix IN 1 .. in_collection_1.COUNT
INSERT INTO your_table(column1, ..., column _n)
VALUES (in_collection_1(ix), ..., in_collection_n(ix))
RETURNING retcolumn_1, ..., retcolumn_n
BULK COLLECT INTO out_collection_1, ... ,out_collection_n ;
? := out_collection_1;
? := out_collection_n;
EXCEPTION
END;Not sure if I've tried this exact thing myself yet, and I won't get into how to pass the collections back and forth here, but I think it can be accomplished in one shot. If your passed collections are of uncomplicated types you might even be able to do it using vanilla JDBC, but Oracle extensions may be required.
Retrieving DML Results into a Collection with the RETURNING INTO Clause
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2241
Working with Oracle Collections
http://download-east.oracle.com/docs/cd/B19306_01/java.102/b14355/oraarr.htm#g1072333
Accessing PL/SQL Index-by Tables
http://download-east.oracle.com/docs/cd/B19306_01/java.102/b14355/oraint.htm#BABBGDFA
Good luck!
-Rick
Edited by: tarpaw on Mar 25, 2010 1:56 PM -
[SOLVED] How to use return parameter of function as paramter of table?
Hi all,
As continue of post "ADF Faces: how to execute pl/sql function when page is loaded." I came up with an other problem where I can't find an easy solution for.
The problem is easy.
1) I execute a procedure, this returns a value
2) I have a table which needs one input parameter
3) How can I bind the return value of the procedure to the input paramter of the table:
A simple example:
1) I created a pl/sql function that returns 1
CREATE FUNCTION zz_return_1
is
RETURN NUMBER
BEGIN
RETURN 1
end;2) I exposed the function in my TestModule so I can use it on a jps page.
3) I created a table TEST_PARAM_1_TABLE with two columns: a, b
4) I created a view read-only object with one paramter
SELECT a,b
FROM zz_scn_test_tab
where a = :var_15) I added the view object to a jps page as tabe > adf read-only
6) I added a methodAction and invokeAction to execute the function on page load
<executables>
<iterator id="zzscntest1Iterator" RangeSize="10" Binds="zzscntest1"
DataControl="TestModuleDataControl"/>
<invokeAction id="runProc" Binds="ftn_return_1"/>
</executables>
<bindings>
<methodAction id="ftn_return_1"
InstanceName="TestModuleDataControl.dataProvider"
DataControl="TestModuleDataControl"
MethodName="ftn_return_1" RequiresUpdateModel="true"
Action="999" IsViewObjectMethod="false"
ReturnName="TestModuleDataControl.methodResults.TestModuleDataControl_dataProvider_ftn_return_1_result"/>
<table id="zzscntest1" IterBinding="zzscntest1Iterator">
<AttrNames>
<Item Value="A"/>
<Item Value="B"/>
</AttrNames>
</table>
</bindings>how can I bind the return value of the function to the var_1 variable of the table?
Additional to this: Is there a way to store the return value in a managed bean?
for example: if I create a managed bean:
public class globalVars {
private Number ftnReturnValue;
public globalVars() {
public void setFtnReturnValue(Number ftnReturnValue) {
System.out.println("return value is set to: " + ftnReturnValue);
this.ftnReturnValue = ftnReturnValue;
public Number getFtnReturnValue() {
return ftnReturnValue;
}how to store the return value in this ftnReturnValue variable?Thanks to Frank,
I finally got it to work!
For those with the same problem, this is what I did:
- I created a VO material_details with one parameter :sequence_num
- I created a master/detail viewlink from my materials list to the materials_details
- In the application module, I created a call to the procedure, and within this procedure, I set the sequence_num variable.
public Number f_ltf3_adf_syf_init(String reporting_group
, String username
, String RAG_code
, String ABC_class
, String SBU_code){
CallableStatement st = null;
String stmt = "M_LTF3_SFM_CALC.f_ltf3_adf_syf_init('"+ reporting_group
+"','"+ username
+"','"+ RAG_code
+"','"+ ABC_class
+"','"+ SBU_code+"')";
try {
// prepare the statement
st = getDBTransaction().createCallableStatement("begin ? := "+stmt+";end;",0);
st.registerOutParameter(1,2); // register output parameter as Number
//execute the statement
st.executeUpdate();
//set paramter in detail VO of master/view
getLtfSyfRevDetails1().setNamedWhereClauseParam("session_seq", (Number)st.getObject(1));
return (Number)st.getObject(1);
}catch (Exception e){e.printStackTrace();}
return null;
} -
Are Sql functions different from user defined functions ?
Hello,
SQL functions are built into Oracle Database and are available for use in various appropriate SQL statements. Do not >confuse SQL functions with user-defined functions written in PL/SQL.according to first paragraph of this document Sql functions are different from user defined functions . How is that ?
Is they really differ from each other ?bootstrap wrote:
If you don't know what compilation is, please use Wikipedia or other online resources.I know what is compilation . But i was confused whether those sql functions are compiled in my machine when i install Oracle Database in my machine or they are pre-compiled .
As you said these Sql functions are pre-compiled , it is clear now that they are pre-compiled platform dependent code .
Can you provide actual source code of any SQL function , say SUM function .
I want to see it, how they have defined . Eagerly waiting for any reply. please help .
Edited by: bootstrap on Aug 19, 2011 11:50 AMYou can ask oracle if they give you their code. I doubt they will. However if you want to write you own user-defined aggregation function, there are examples in the documentation how to do that.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_packages.htm#i1008575
Edited by: Sven W. on Aug 19, 2011 9:24 AM
Maybe you are looking for
-
Macbook Pro 15-inch, late 2011 - Wacom Cintiq 21UX 2
Today i was asked to hook up a Wacom Cintiq 21UX to a brand new MBP... After hooking up all the cables the Cintiq started displaying distortion, like a noise in the vertical lines of the screen. Wacom suggests to check the cables and try a different
-
How to align text {center/left/right} in the column of ALV grid
Hai all, I am displaying one check box in the ALV grid, but default it is coming left align in the column, how can i assign it to the center of the column. Thanks, SREEVATHSAVA.G Edited by: SREE on Aug 14, 2009 7:53 AM
-
How do I open older versions of Pages in Maverick?
All my work is saved in the older version of iWorks (Pages). This new Maverick won't open it. I have been able to open my older photos with iPhoto Library Upgrader but need to know how to open my older documents in Pages. Is there an app or progr
-
Server does not respond my Activacion! Server is Broken!
Hi every one, i cant activate my iphone 5 and server does not respond my Activacion
-
I have an ipad, iphone, imac and considering buying Apple tv but I want to make sure it's what I need. Can I stream from any of these devices with anything to the apple tv? If I am watching hulu on my ipad, can I stream to my tv via apple tv. In ot