Return a recordset in script or procedure
Hi ALL,
How can I use "select * "statement in script or procedure?
Example
DECLARE
V_PRVSP_REFNO Number;
BEGIN
select * from tb;
END;
You can use ref cursor, example for you:
[email protected]> create or replace procedure test_ref(p_ref out sys_refcursor)
2 is
3 begin
4 open p_ref for select * from dept;
5 end;
6 /
Procedure created.
[email protected]> variable xcur refcursor
[email protected]> exec test_ref(:xcur)
PL/SQL procedure successfully completed.
[email protected]> print :xcur
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Best Regards
Krystian Zieja / mob
Similar Messages
-
How to test a procedure which returns a recordset from pl/sql
hello,
Is it possible to test a procedure which returns a recordset from pl/sql?
Everything I try results in errors like PLS-00382: expression is of wrong type, when I try to open the result cursor
or PLS-00221: tc is not a procedure or is undefined.
I created the following procedure:
CREATE OR REPLACE PACKAGE test AS
TYPE cursorType is REF CURSOR;
PROCEDURE test_cursor( tc IN OUT cursorType,
v_err OUT varchar2,
v_msg OUT varchar2);
END;
CREATE OR REPLACE
PACKAGE BODY test AS
PROCEDURE test_cursor
(tc IN OUT cursorType,
v_err OUT varchar2,
v_msg OUT varchar2)
AS
BEGIN
open tc for
SELECT '1' "number" FROM dual
union
select '2' "number" from dual;
v_msg := 'no errors';
v_err := 0;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
v_msg := 'no data found';
v_err := SQLCODE;
WHEN OTHERS
THEN
v_msg := SQLERRM;
v_err := SQLCODE;
END;
END;
I try to get the output from pl/sql with something like this:
DECLARE
TC PROVGRON.TEST.cursorType;
V_ERR VARCHAR2(200);
V_MSG VARCHAR2(200);
BEGIN
V_ERR := NULL;
V_MSG := NULL;
PROVGRON.TEST.TEST_CURSOR ( TC, V_ERR, V_MSG );
DBMS_OUTPUT.Put_Line('V_ERR = ' || V_ERR);
DBMS_OUTPUT.Put_Line('V_MSG = ' || V_MSG);
-- in tc I was hoping to hava a cursor??
FOR i IN tc
LOOP
DBMS_OUTPUT.PUT_LINE (i.number);
END LOOP;
END;
Without the for loop (or open tc) the pl/sql will output:
V_ERR = 0
V_MSG = no errors
PL/SQL procedure successfully completed.
With anything I try with the cursor I get errors?
What am I doing wrong?http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1122
-
Procedure to return a recordset in ASP.
I'll admint that my background is with MS SQL and Oracle is a bit different!
In SQL I can create a stored procedure that will return a recordset, filtered by the parameter that I pass to the procedure. Such as:
CREATE PROCEDURE sp_DriverList @BusCoID int
AS
SELECT DISTINCT ListName, DriverID
FROM T_Drivers
WHERE BusCoID = @BusCoID
ORDER BY ListName
In ASP I get back a list of all the Drivers for a given company, using the @BusCoID parameter.
When I try to implement this same method in Oracle 9i, I get an error. Can someone provide an example, comparable to the SQL version above, that would return a recordset?
Thanks!!!Your post will likely get a better response on the ODP.NET forum, but here's how I would do it.
CREATE OR REPLACE PACKAGE my_package
IS
TYPE refc IS REF CURSOR
RETURN t_drivers%ROWTYPE refc;
Function fetch_drivers(p_busid_in IN number);
END my package;
CREATE OR REPLACE PACKAGE BODY my_package
IS
Function fetch_drivers (p_busid_in IN number)
IS
l_curser refc;
BEGIN
OPEN l_cursor FOR
SELECT DISTINCT ListName, DriverID
FROM T_Drivers
WHERE BusCoID = p_busid_in
ORDER BY ListName;
RETURN l_cursor;
END fetch_drivers; -
Updateable recordset from a stored procedure
I would like to retrieve an updateable recordset from a stored procedure using the oracle 9.2.0.2.0
oledb provider
I am using the sample code/tables provided from Oracle.
Does anyone have an example or has actually created an updatedable recordset from a stored procedure ?Assuming your stored procedure is returning a REF CURSOR, it cannot be done. Oracle's REF CURSORS are read only constructs.
Justin -
How to get an updatable ADODB Recordset from a Stored Procedure?
In VB6 I have this code to get a disconnected ADODB Recordset from a Oracle 9i database (the Oracle Client is 10g):
Dim conSQL As ADODB.Connection
Dim comSQL As ADODB.Command
Dim recSQL As ADODB.Recordset
Set conSQL = New ADODB.Connection
With conSQL
.ConnectionString = "Provider=OraOLEDB.Oracle;Password=<pwd>;Persist Security Info=True;User ID=<uid>;Data Source=<dsn>"
.CursorLocation = adUseClientBatch
.Open
End With
Set comSQL = New ADODB.Command
With comSQL
.ActiveConnection = conSQL
.CommandType = adCmdStoredProc
.CommandText = "P_PARAM.GETALLPARAM"
.Properties("PLSQLRSet").Value = True
End With
Set recSQL = New ADODB.Recordset
With recSQL
Set .Source = comSQL
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open
.ActiveConnection = Nothing
End With
The PL/SQL Procedure is returning a REF CURSOR like this:
PROCEDURE GetAllParam(op_PARAMRecCur IN OUT P_PARAM.PARAMRecCur)
IS
BEGIN
OPEN op_PARAMRecCur FOR
SELECT *
FROM PARAM
ORDER BY ANNPARAM DESC;
END GetAllParam;
When I try to update some values in the ADODB Recordset (still disconnected), I get the following error:
Err.Description: Multiple-step operation generated errors. Check each status value.
Err.Number: -2147217887 (80040E21)
Err.Source: Microsoft Cursor Engine
The following properties on the Command object doesn't change anything:
.Properties("IRowsetChange") = True
.Properties("Updatability") = 7
How can I get an updatable ADODB Recordset from a Stored Procedure?4 years later...
I was having then same problem.
Finally, I've found how to "touch" the requierd bits.
Obviously, it's hardcore, but since some stupid at microsoft cannot understand the use of a disconnected recordset in the real world, there is no other choice.
Reference: http://download.microsoft.com/downlo...MS-ADTG%5D.pdf
http://msdn.microsoft.com/en-us/library/cc221950.aspx
http://www.xtremevbtalk.com/showthread.php?t=165799
Solution (VB6):
<pre>
Dim Rst As Recordset
Rst.Open "select 1 as C1, '5CHARS' as C5, sysdate as C6, NVL(null,15) as C7, null as C8 from DUAL", yourconnection, adOpenKeyset, adLockBatchOptimistic
Set Rst.ActiveConnection = Nothing
Dim S As New ADODB.Stream
Rst.Save S, adPersistADTG
Rst.Close
Set Rst = Nothing
With S
'Debug.Print .Size
Dim Bytes() As Byte
Dim WordVal As Integer
Dim LongVal As Long
Bytes = .Read(2)
If Bytes(0) <> 1 Then Err.Raise 5, , "ADTG byte 0, se esperaba: 1 (header)"
.Position = 2 + Bytes(1)
Bytes = .Read(3)
If Bytes(0) <> 2 Then Err.Raise 5, , "ADTG byte 9, se esperaba: 2 (handler)"
LongVal = Bytes(1) + Bytes(2) * 256 ' handler size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 3 Then Err.Raise 5, , "ADTG, se esperaba: 3 (result descriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' result descriptor size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 16 Then Err.Raise 5, , "ADTG, se esperaba: 16 (adtgRecordSetContext)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 5 Then Err.Raise 5, , "ADTG, se esperaba: 5 (adtgTableDescriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(1)
If Bytes(0) <> 6 Then Err.Raise 5, , "ADTG, se esperaba: 6 (adtgTokenColumnDescriptor)"
Do ' For each Field
Bytes = .Read(2)
LongVal = Bytes(0) + Bytes(1) * 256 ' token size
Dim NextTokenPos As Long
NextTokenPos = .Position + LongVal
Dim PresenceMap As Long
Bytes = .Read(3)
PresenceMap = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(2)), 2))
Bytes = .Read(2) 'ColumnOrdinal
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
'Aca pueden venir: friendly_columnname, basetable_ordinal,basetab_column_ordinal,basetab_colname
If PresenceMap And &H800000 Then 'friendly_columnname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
If PresenceMap And &H400000 Then 'basetable_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H200000 Then 'basetab_column_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H100000 Then 'basetab_colname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
Bytes = .Read(2) 'adtgColumnDBType
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
Bytes = .Read(4) 'adtgColumnMaxLength
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Precision
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Scale
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Dim ColumnFlags() As Byte, NewFlag0 As Byte
ColumnFlags = .Read(1) 'DBCOLUMNFLAGS, First Byte only (DBCOLUMNFLAGS=4 bytes total)
NewFlag0 = ColumnFlags(0)
If (NewFlag0 And &H4) = 0 Then 'DBCOLUMNFLAGS_WRITE (bit 2) esta OFF
'Lo pongo en ON, ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 Or &H4)
End If
If (NewFlag0 And &H8) <> 0 Then 'DBCOLUMNFLAGS_WRITEUNKNOWN (bit 3) esta ON
'Lo pongo en OFF, ya que no me importa si NO sabes si se puede updatear no, yo lo se, no te preocupes
'ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 And Not &H8)
End If
If (NewFlag0 And &H20) <> 0 Then 'DBCOLUMNFLAGS_ISNULLABLE (bit 5) esta OFF
'Lo pongo en ON, ya que siendo un RST DESCONECTADO, si le quiero poner NULL, le pongo y listo
NewFlag0 = (NewFlag0 Or &H20)
End If
If NewFlag0 <> ColumnFlags(0) Then
ColumnFlags(0) = NewFlag0
.Position = .Position - 1
.Write ColumnFlags
End If
.Position = NextTokenPos
Bytes = .Read(1)
Loop While Bytes(0) = 6
'Reconstruyo el Rst desde el stream
S.Position = 0
Set Rst = New Recordset
Rst.Open S
End With
'TEST IT
On Error Resume Next
Rst!C1 = 15
Rst!C5 = "MUCHOS CHARS"
Rst!C7 = 23423
If Err.Number = 0 Then
MsgBox "OK"
Else
MsgBox Err.Description
End If
</pre> -
Hi,
How do I return two values from a
stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
Something like ?
CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
@intPeriod INT,
@strPeriod_Length NVARCHAR(1),
@dtStart NVARCHAR(8) OUTPUT,
@dtEnd NVARCHAR(8) OUTPUT
AS
then within the SSIS component; -
Kind Regards,
Kieran.
Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
Add a script task to check ssis variables values using,
Msgbox(Dts.Variables("User::strExtractStartDate").Value)
Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
Regards, RSingh -
Problem using script stored procedure as using EXEC dbo.sp_executesql
When I use the Script Stored Procedure AS Create or Drop And Create I want to get the stored procedure returned like in 2008 some how I have missed a setting and I am getting it like this. I get the sp_executesql instead of just the create procedure
and if I use a single quote it encloses them in single quotes. Can some one please give me the setting I can't find it?
IF
NOTEXISTS(SELECT*FROMsys.objectsWHEREobject_id=OBJECT_ID(N'[dbo].[usp_record_count]')ANDtypein(N'P',N'PC'))
BEGIN
EXEC
dbo.sp_executesql@statement
=N'--DECLARE
@tablename AS sysname;
--SET @tablename = ''[Production].[Product]''
CREATE PROCEDURE [dbo].[usp_record_count]
(@tablename sysname)
AS
BEGIN
SET NOCOUNT OFF
EXECUTE (''SELECT COUNT(*) FROM '' + @tablename)
END
END
Thank you for you help!!!!
AntonioIf you have Include IF NOT EXISTS clause
to TRUE
then SQL wraps
the script in a sp_executesql statement no matter how you generate the script including above cases. To get rid of SQL wraps
the sp_executesql statement need to set it to FALSE.
AFAIK only alternative is to use
sp_helptext 'proc_name'
Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
Praveen Dsa | MCITP - Database Administrator 2008 |
My Blog | My Page -
Return a Recordset in a PL/SQL
Hello All,
I'm attempting to write a PL/SQL statement over some very large tables. The processing of the statement takes over 45 minutes to complete.
I've been able to speed up processing by creating a temp table over the largest of the tables, and it truly has speed up processing. The problem is that this statement will be used in a report run from SQL Reporting Services, using PL/SQL. This will be used in various reports and would like to make this an adhoc type of job - launched by executing the report.
I've tried writing a procedure that returns a recordset, but I'm having no luck. I'm new to writing Stored Procedures, Functions and Packages, and am trying to get my head around the best way to approach this.
Here is what I have so far - and it's not even close to working, but you can see the logic I'm trying to follow as far was what I need to return.
CREATE OR REPLACE PACKAGE PKG_BillSegs_ZeroUsage AS
TYPE cursor_type IS REF CURSOR;
Procedure GETBILLSEG_ZEROUSAGE (
p_RevMth IN bi_bill_segment.rev_month%TYPE,
p_recordset OUT PKG_BillSegs_ZeroUsage.cursor_type);
END PKG_BillSegs_ZeroUsage;
CREATE OR REPLACE PROCEDURE GetBillSeg_ZeroUsage (p_RevMth IN bi_bill_segment.rev_month%TYPE,
p_recordset OUT PKG_BillSegs_ZeroUsage.cursor_type) AS
BEGIN
OPEN p_recordset FOR
select * from bi_bill_segment where usage_qty = 0 and rev_month = p_RevMth;
END GetBillSeg_ZeroUsage;
Any help is greatly appreciated!Here's the output from explain plan - sorry for the output, but couldn't get it to be any prettier :
OPERATION OPTIONS OBJECT_NAME OBJECT_TYPE OPTIMIZER SEARCH_COLUMNS ID PARENT_ID POSITION COST CARDINALITY BYTES
SELECT STATEMENT REMOTE CHOOSE 0 91911 91911 2 4902
TABLE ACCESS BY INDEX ROWID BI_BILL_SEGMENT_T ANALYZED 1 0 1 91911 2 4902
INDEX RANGE SCAN BI_BILL_SEGMENT_IE7 NON-UNIQUE ANALYZED 1 2 1 1 659 178774 -
Returning 2D array from a stored procedure
hi,
i'm trying to return a nested table from a procedure.can any one help me out i'm getting the fallowing error.
SQL> ed
Wrote file afiedt.buf
1 declare
2 TYPE data_t IS TABLE OF NUMBER
3 INDEX BY PLS_INTEGER;
4 TYPE array_t IS TABLE OF data_t
5 INDEX BY PLS_INTEGER;
6 array array_t;
7 begin
8 Sp_test(123,'12-jan-08',array);
9 dbms_output.put_line(array (10) (1));
10* end;
11 /
Sp_test(123,'12-jan-08',array);
ERROR at line 8:
ORA-06550: line 8, column 1:
PLS-00306: wrong number or types of arguments in call to
'SP_TEST
ORA-06550: line 8, column 1:
PL/SQL: Statement ignored
The procedure is
CREATE OR REPLACE PROCEDURE Sp_test(S_KEY NUMBER,V_DATE DATE, array_out OUT array_t) as....Below is the error i got when using the above suggestion.
SQL> ED
Wrote file afiedt.buf
1 DECLARE
2 TYPE data_t IS TABLE OF NUMBER
3 INDEX BY PLS_INTEGER;
4 TYPE array_t IS TABLE OF data_t
5 INDEX BY PLS_INTEGER;
6 begin
7 Sp_test(123,'12-jan-08',array REPORT.ARRAY_T);
8 dbms_output.put_line(array (10) (1));
9* end;
10 /
Sp_test(123,'12-jan-08',array REPORT.ARRAY_T);
ERROR at line 7:
ORA-06550: line 7, column 32:
PLS-00103: Encountered the symbol "REPORT" when expecting one of the
following:
. ( ) , * @ % & | = - + < / > at in is mod not range rem =>
.. <an exponent (**)> <> or != or ~= >= <= <> and or like
between ||
The symbol "." was substituted for "REPORT" to continue. -
Returning a table from a stored procedure
hi, i need to return a table from a stored procedure and show it, and come to this, but a don't know hoy to run it, so i don't know if it is right, can anyone help me?
uTable out objects_uptime%rowtype
as
begin
select * into uTable from objects_uptime;
end;well, i finally discovered how to do the trick
this is the code for the function:
CREATE OR REPLACE FUNCTION FN_GET_RECORDS RETURN UPTIME PIPELINED IS
CURSOR cUptime is select * from objects_uptime;
p refcur.refcur_t;
temp p%ROWTYPE;
temp2 OUPTIME := OUPTIME(null, null, null, null, null, null, null, null, null);
BEGIN
OPEN cUptime;
LOOP
FETCH cUptime into temp;
temp2.OBJ_NAME := temp.OBJ_NAME;
temp2.IP := temp.IP;
temp2.STATUS := temp.STATUS;
temp2.DOE := temp.DOE;
temp2.ENABLED := temp.ENABLED;
temp2.COMMENT00000 := temp.COMMENT00000;
temp2.USERID := temp.USERID;
temp2.OBJECTID := temp.OBJECTID;
temp2.MNTID := temp.MNTID;
pipe row(temp2);
EXIT WHEN cUptime%NOTFOUND;
END LOOP;
RETURN;
END FN_GET_RECORDS;
and this for the auxiliar package, object and table:
CREATE OR REPLACE PACKAGE REFCUR
as
TYPE refcur_t IS REF CURSOR RETURN objects_uptime%ROWTYPE;
end REFCUR;
CREATE OR REPLACE TYPE OUPTIME AS OBJECT ( "OBJ_NAME"
VARCHAR2(255), "IP" VARCHAR2(20), "STATUS" VARCHAR2(10),
"DOE" DATE, "ENABLED" NUMBER(10, 1), "COMMENT00000"
VARCHAR2(1000), "USERID" VARCHAR2(50), "OBJECTID" NUMBER(10,
1), "MNTID" NUMBER(10, 1) )
CREATE TYPE TUPTIME AS
TABLE OF OUPTIME
i call it this way:
select * from table(FN_GET_RECORDS ())
if anyone knows how to do the same in a shorter manner, tell me please.
thanks to everybody for the help. -
Howto:pass an ado.recordset to a stored procedure
Hi,
I need to pass an adodb.recordset to a stored procedure in Oracle 8.0.5.
I am programming with visualbasic 6, an exe application.
I don4t know how to setting the parameter for the adodb.command which execute the procedure.
Any idea??
Thanks,
Cesar,Hi,
You can't do this using an OLEDB provider. There is no such a provider with this feature.
Yuancai (Charlie) Ye
See 30 real well-tested advanced OLEDB samples
Use of free SocketPro for creating super client and server application with numerous samples
www.udaparts.com -
How to return a resultset in a stored procedure without using Cursor
Dear all,
I need to return a resultset in a stored procedure.
I know I can return a Cursor.
But because there are many complicate logics I need to carry out,
so I can finish all the logic in a SINGLE SQL select statement, so I think it can't
use Cursor as return value.
Does anybody know other approaches? Please help.
Thanks!Some basic techniques that one can use in SQL. These are merely to illustrate (simplistically) different approaches.
> field3 = select count(*) from table2,table1 where table2.id = table1.id
This can be done via an analytical function (refer to the SQL Reference) or very simply, as an in-line select as follows:
SQL> select
2 o.object_name,
3 (select count(*) from user_objects u where u.object_type = o.object_type) as "ONE OF",
4 o.object_type
5 from user_objects o
6 where o.object_name = 'LISTFILES';
OBJECT_NAME ONE OF OBJECT_TYPE
LISTFILES 8 PROCEDURE
So LISTFILE is "one of 8" procedures. I would however rather so this via an analytic function as these are a lot more flexible. Note the WITH clause that allows "modularisation" of SQL - kind of like creating "sub-SQL results" in a single SQL statement:
SQL> with DATASET1 as(
2 select
3 object_name,
4 count(distinct object_name) over (partition by object_type) as TOTAL_TYPES,
5 object_type
6 from user_objects
7 ),
8 DATASET2 as(
9 select
10 name,
11 text as SOURCE_LINE,
12 line as LINE_NO,
13 count(line) over (partition by name) as TOTAL_LINES
14 from user_source
15 )
16 select
17 object_name,
18 '1 of '||total_types||' '||object_type as "TYPE",
19 source_line as "1st LINE",
20 total_lines as "TOTAL LINES"
21 from DATASET1 ds1,
22 DATASET2 ds2
23 where ds1.object_name = ds2.name
24 and ds1.object_name = 'LISTFILES'
25* and ds2.line_no = 1
SQL> /
OBJECT_NAME TYPE 1st LINE TOTAL LINES
LISTFILES 1 of 8 PROCEDURE procedure ListFiles( cDirectory in varchar2 ) 3
SQL>
SQL is quite powerful and analytical functions allows all kinds of aggregation processing per row, accessing the leading or lagging rows' data, etc.
You need to play around with this to get to grips with it and how to apply it. -
Return a record set from a procedure
I am building an application for my company.
Before oracle I had used MS SQL Server for a long time.
I build a procedure as following
CREATE OR REPLACE PROCEDURE YBP.ReturnSet
-- Return a record set from a procedure
IS
BEGIN
SELECT * FROM fdbase;
END;
But the complier show me a error message:
<font color="#0000FF">PLS-00428 an INTO clause is expected in this SELECT statement</font>
I read the error details
<font color="#0000FF">"In PL/SQL, only a subquery is written without an INTO clause."</font>
But I know that this procedure can run well in <font color="#0000FF">MS SQL Server .</font>
How I can do this thing in Oracle
Any help will be appreciate!I have a stored proc that is defined as
CREATE or REPLACE
PROCEDURE ABC
(linkid IN CHAR,
Year_in IN DATE,
Method_in IN CHAR,
Date_out OUT DATE,
average_out OUT NUMBER)
is
begin
.. Date_out := ...;
average_out := ...;
end;
another partially completed stored proc that returns a ref
cursor defined as follows:
create or replace package zzz
as
type cursorType is ref cursor;
end;
create or replace function test return zzz.cursortype
as
date_OUT date;
Average_OUT number;
l_cursor zzz.cursorType;
CURSOR temp_cur is
SELECT l.linkid, L.routenumber, ABC(l.linkid,
to_date('01/01/2000', 'mm/dd/yyyy'),
'2',
date_OUT,
average_OUT)
FROM LINK l
WHERE l.LINKID <= '010999';
begin
open temp_cur;
end;
inside test (which I need help completing), how can I refer to
the date_out and the average_out params returned by ABC() so
that these values are in turn passed to the cursortype defined
in package zzz?
Thanks in advance. -
How to return object type from external c procedure ?
Hello all,
I'm trying for the first time to return an object type as the return value of an external stored procedure (in C ).
I don't have any issue to use an object type parameter for the function but not to return one to the caller.
each time I try I get "ORA-03113: end-of-file on communication channel" and the connection is dropped.
Thanks for any help,
Roye Avidor
here is the code :
=> object type
SQL>create or replace type address as object ( age number, salary float );
=> address typ file
CASE=SAME
TYPE address as address
=> building the dependences structures.
$>ott userid=scott/tiger intype=address.type code=c hfile=address.h
=> the package description
create or replace package userTypeDefined_PKG
is
function getAddr( addr address ) return address;
end;
create or replace package body userTypeDefined_PKG
is
function getAddr( addr address ) return address
AS LANGUAGE C
NAME "addr"
LIBRARY userTypeDefinedLib
WITH CONTEXT
PARAMETERS
( CONTEXT,
addr,
addr INDICATOR STRUCT ,
return address,
return INDICATOR STRUCT
end;
=> The C code for the library in
address* addr(OCIExtProcContext ctx, address address_obj, address_ind address_obj_ind, address_ind ret_ind){
unsigned int tt;
OCIEnv *envh;
OCIError *errh;
OCISvcCtx *svch;
sword err;
address* ret = NULL;
int inum = 69;
float fnum = 12.34;
/* get OCI Environment */
err = OCIExtProcGetEnv(ctx, &envh, &svch, &errh) ;
/* allocate space for return sturcture*/
ret = (address *)OCIExtProcAllocCallMemory(ctx, sizeof(address));
/* set the AGE value */
if ( OCINumberFromInt ( errh, &inum, sizeof(inum), OCI_NUMBER_SIGNED, &(ret->AGE) ) == OCI_ERROR )
OCIExtProcRaiseExcp(ctx,(int)1476); // raise 1476 is fail
/* set the SALARY value */
if ( OCINumberFromReal ( errh, &fnum, sizeof(fnum), &(ret->SALARY) ) == OCI_ERROR )
OCIExtProcRaiseExcp(ctx,(int)1477);// raise 1477 is fail
// set the indicators for the structure as not null
ret_ind->atomic = OCIIND_NOTNULL;
ret_ind->AGE = OCI_IND_NOTNULL;
ret_ind->SALARY = OCI_IND_NOTNULL;
return (ret);
}The return indicator should be declared as double pointer, and need to be allocated in the function body.
-
How to return a recordset (SQL)
I would like to know if it is possible to return a record set from a procedure and if so how?
Thanks in advance for any help.If you find out how to... could you please let me know it...
Thanks... I'm looking for the same thing.
my email: [email protected]
Maybe you are looking for
-
have Creative Cloud Subscription- Windows 7 ultima--16GB ram memory-Photoshop cc 2014 updated- I cannot find the Creative Cloud Libraries instead I get My Libraries that I have not created- I cannot find the Assets tab. Tried several links no solutio
-
Broken Link for JDBC 8.1.7.1 driver
I'm trying to dowlond the classes12.zip from http://otn.oracle.com/software/tech/java/sqlj_jdbc/htdocs/jdbc817.html. Keep getting a page not found when I click on the link
-
Hyperion Planning - extract text from Planning
We have an account with the following properties: Account Type: SavedAssumption Data Type: Text We need to extract the text that is captured on the account. The data form we created works but is to big for SmartView and extracting it with Ad-hock Ana
-
Adding BKPF_XREF1_HD field for FBL3n and FBL1N dynamic selection
Hi Friends, Is there any possible way to add the BKPD-XREF1_HD field to FBL1N and FBL3N transactions? As per my knowledge both are line item related process which contains other than BKPF table entries. Bue my client wants to add in the Dynamic selec
-
Hi, I Clicked to download GTA San Andreas from the app store and some sort of problem occurred and the download automatically cancelled. Now it won't let me re-download and in purchases it says an error has occurred and doesn't show "Install" in the