Several ways in which a function/procedure in Oracle Returns a result set:
In the case of function return, the stored procedure can only be changed to out parameters and passed in the Oracle 10g test.
(1) Return cursor:
The return type is: Sys_refcursor
Then define the variables in the is: Curr Sys_refcursor;
Finally, write in the body of the function:
Open cur for
Select ...;
return cur;
Cases:
CREATE OR REPLACE FUNCTION a_test (
Ortype VARCHAR2
) Return Sys_refcursor
Is
Type_cur Sys_refcursor;
BEGIN
OPEN Type_cur for
Select Col1,col2,col3 from TestTable;
return type_cur;
End;
(2) Returns the result set of the table type:
First, define a row type:
CREATE OR REPLACE TYPE "Split_arr" as OBJECT (nowstr varchar2 (18))
Second, define a table type with this row type:
CREATE OR REPLACE TYPE "Split_tab" as TABLE of Split_arr;
Define function (This function completes the string split function):
CREATE OR REPLACE FUNCTION getsubstr (
Str in VARCHAR2,--strings to be split
Splitchar in VARCHAR2--split flag
)
Return Split_tab
Is
Reststr VARCHAR2 (Watts) default GETSUBSTR. STR; --The remaining strings
Thisstr VARCHAR2 (18); --the current string obtained
INDEXSTR int; --Place the separator temporarily in the string
V Split_tab: = Split_tab (); --Return results
Begin
Dbms_output.put_line (RESTSTR);
While length (RESTSTR)!= 0
LOOP
<< Top >>
Indexstr: = InStr (Reststr,splitchar); --the first position to take a separator from a substring
If Indexstr = 0 and Length (reststr)!= 0 then-delimiter not found in remaining string
Begin
V.extend;
V (v. count): = Split_arr (RESTSTR);
return v;
End;
End If;
If indexstr = 1 then---the first character is a separator, the separator is removed at this time
Begin
RESTSTR: = substr (Reststr, 2);
Goto top;
End;
End If;
If Length (reststr) = 0 or reststr is null then
return v;
End If;
V.extend;
THISSTR: = substr (Reststr, 1, indexStr-1); --Get the current string
RESTSTR: =
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service