Returning Oracle Output Parameters from Stored Procedures
Hi,
Please forgive my ignorance of Oracle and PL/SQL. I'm trying to get a value out of a stored proc which I've written. The proc takes a username input parameter and returns a user guid through an output parameter. I'm able to print the output parameter to the DBMS Output but can't figure out how to return the thing in a record when calling the proc through a normal sql prompt!
My call is like so:
DECLARE
nGUID NVARCHAR2(255);
BEGIN
GETUSER(nGUID, 'WHY-DEV-QSYS-Tim Watson');
DBMS_OUTPUT.PUT_LINE (nGUID);
Would like to return the value here; what's the syntax?
END;
The signature of the proc is
CREATE OR REPLACE PROCEDURE GETUSER
USERGUID OUT NVARCHAR2,
UNAME IN NVARCHAR2
IS
Can anyone assist?
Thanks in advance!
Tim
The easiest way, in my opinion, is to not write a procedure, but a function for this porpose. You would not have to declare an out parameter, but a return value:
CREATE OR REPLACE FUNCTION GETUSER
UNAME IN NVARCHAR2
return nvarchar2
IS
From SQL prompt, you can then do
SQL> select getuser(<input_string>) from dual;
and get the returnvalue.
Best regards,
Gerd
Similar Messages
-
Returning rowcount and resultset from stored procedure
Hello,
In SQL Server you can return multiple resultsets from stored procedure by simple SELECT statement. But in Oracle, you have to use SYS_REFCURSOR.
Sample code:
CREATE OR REPLACE PROCEDURE sp_resultset_test IS
t_recordset OUT SYS_REFCURSOR
BEGIN
OPEN t_recordset FOR
SELECT * FROM EMPLOYEE;
END sp_resultset_test;
Is there any other way in Oracle 10 or 11 ?
Thank You.What is the requirement? Oracle is far more flexible than SQL-Server... with numerous features that do not exist in SQL-Server. (Fact)
One of the biggest mistakes you can make is to treat Oracle like SQL-Server... trying to match feature A1 in SQL-Server to feature B3 in Oracle.
Does not work that way.. rather then stick to SQL-Server as SQL-Server does SQL-Server specific features far better than Oracle.
So instead of trying to map what a T-SQL stored proc to do to an Oracle ref cursor (even to the extent of using that very silly sp_ prefix to name the proc), tell us the problem and requirements... That way we can tell you what Oracle features and options are best used to solve that problem - instead of competing in some unknown feature comparison event with SQL-Server. -
How to retrieve Table of Records output param from stored procedure ?
Hi,
I'm trying to retrieve data from a PL/SQL stored proc. It seems I can't modify this procedure (I'm not allowed to and I don't know PL/SQL :)).
My only documentation is the PL/SQL code and its comments. And that's the first I have to deal with output of a defined complex PL/SQL type
So the signature of the procedure is :
FUNCTION FUN_AFF_EVELEG_IHM (
pEntumTyp IN NUMBER,
pEntnum IN VARCHAR2,
pEveListSize IN OUT NUMBER,
pEveList IN OUT pkg_funaff_eveleg.TableRecordEVL,
pErrCode IN OUT VARCHAR2,
pMessage IN OUT VARCHAR2)
RETURN NUMBER;pkg_funaff_eveleg.TableRecordEVL type is defined as "TABLE of RecordEVL"
pkg_funaff_eveleg.RecordEVL type is defined as "RECORD" (struct of 12 different fields : NUMBER or VARCHAR2)
What is the correct syntax to call the stored procedure then ? I don't find how to manage the pEveList output param. Is it a Cursor ? An ARRAY ? And how to register it ?
My code so far :
public static void callFunaffEVL(Connection con, String rcs) {
// CallableStatement procCstmt=null;
OracleCallableStatement oraCstmt = null;
try {
// Identifiy the Stored procedure
// package synonyme : pkg_aff_EVELEG_IHM
// stored procedure name : FUN_AFF_EVELEG_IHM
String command = new StringBuilder("{? = call pkg_aff_EVELEG_IHM.FUN_AFF_EVELEG_IHM(?,?,?,?,?,?");
// 1 RETURN
// 2 pEntumTyp IN NUMBER
// 3 pEntnum IN VARCHAR2
// 4 pEveListSize IN OUT NUMBER,
// 5 pEveList IN OUT pkg_funaff_eveleg.TableauRecordEVL,
// 6 pErrCpde IN OUT VARCHAR2,
// 7 pMessage IN OUT VARCHAR2)
// Create a Callable Statement Object:
oraCstmt = (OracleCallableStatement) con.prepareCall(command);
// Assign IN and OUT parameters
oraCstmt.registerOutParameter(1, OracleTypes.NUMBER); // RET
oraCstmt.setInt(2, 0); // ENTNUMTYP
oraCstmt.setString(3, rcs); // ENTNUM
oraCstmt.registerOutParameter(4, OracleTypes.NUMBER); // pEveListSize
oraCstmt.registerOutParameter(5, OracleTypes.ARRAY); // pEveList
oraCstmt.registerOutParameter(6, OracleTypes.VARCHAR); // pErrCode
oraCstmt.registerOutParameter(7, OracleTypes.VARCHAR); // pMessage
// Execute the Procedure or Function Call:
oraCstmt.execute();
// Process the OUT Placeholders:
int ret = oraCstmt.getInt(1);
String errCode = oraCstmt.getString(6);
String message = oraCstmt.getString(7);
System.out.println("RCS : " + rcs);
System.out.println("ret : " + ret);
System.out.println("errCode : " + errCode );
System.out.println("message : " + message);
} catch (SQLException sqle) {
sqle.printStackTrace();
} finally {
// Close the CallableStatement Object:
try {
oraCstmt.close();
} catch (SQLException e) {
e.printStackTrace();
Return : java.sql.SQLException: Parameter type Conflict: sqlType=2003
Any help ? I found several examples that might refer to this case, but everything I tried end by a SQL exception of one type or another...
(and sorry for my poor english :))
CyAs I said, "pkg_funaff_eveleg.TableRecordEVL" is TABLE of RecordEVL.
i.e : I can find 2 defined types under the package pkg_funaff_eveleg :
TYPE TableRecordEVL is TABLE of RecordEVL INDEX BY BINARY_INTEGER;
TYPE RecordEVL is RECORD (
EVLENTNUM_PK EVENEMENTS_LEGAUX.EVLENTNUM_PK%TYPE,
EVLENTNUMTYP_PK EVENEMENTS_LEGAUX.EVLENTNUMTYP_PK%TYPE,
EVLSEQ_PK EVENEMENTS_LEGAUX.EVLSEQ_PK%TYPE,
EVLTYPSRC EVENEMENTS_LEGAUX.EVLTYPSRC%TYPE,
EVLPK1 EVENEMENTS_LEGAUX.EVLPK1%TYPE,
EVLPK2 EVENEMENTS_LEGAUX.EVLPK2%TYPE,
EVLPK3 EVENEMENTS_LEGAUX.EVLPK3%TYPE,
EVLPK4 EVENEMENTS_LEGAUX.EVLPK4%TYPE,
EVLPK5 EVENEMENTS_LEGAUX.EVLPK5%TYPE,
EVLPK6 EVENEMENTS_LEGAUX.EVLPK6%TYPE,
EVLCODEVTSRC EVENEMENTS_LEGAUX.EVLCODEVTSRC%TYPE,
EVLLEGEVECOD EVENEMENTS_LEGAUX.EVLLEGEVECOD%TYPE,
EVLSEQREF_FK EVENEMENTS_LEGAUX.EVLSEQREF_FK%TYPE,
EVLCOMMENT EVENEMENTS_LEGAUX.EVLCOMMENT%TYPE,
EVLETATCOD EVENEMENTS_LEGAUX.EVLETATCOD%TYPE,
EVLHISDATPUB EVENEMENTS_LEGAUX.EVLHISDATPUB%TYPE,
EVLHISPUBPRE EVENEMENTS_LEGAUX.EVLHISPUBPRE%TYPE,
EVLHISDATEFF EVENEMENTS_LEGAUX.EVLHISDATEFF%TYPE,
EVLHISEFFPRE EVENEMENTS_LEGAUX.EVLHISEFFPRE%TYPE,
EVLHISPOIDATEFF EVENEMENTS_LEGAUX.EVLHISPOIDATEFF%TYPE,
EVLHISORICOD EVENEMENTS_LEGAUX.EVLHISORICOD%TYPE,
EVLHISSUPPORTCOD EVENEMENTS_LEGAUX.EVLHISSUPPORTCOD%TYPE,
EVLHISNUMSUPPORT EVENEMENTS_LEGAUX.EVLHISNUMSUPPORT%TYPE,
EVLHISNUMINF EVENEMENTS_LEGAUX.EVLHISNUMINF%TYPE,
ANNNUMBODPCL CBODACCPROD.CODANN2.ANNNUMBOD%TYPE
);If needed, I can translate each "EVENEMENTS_LEGAUX.EVLENTNUM_PK%TYPE", but they must be VARCHAR2 or NUMBER
Do I answer your question ? -
How to output value from stored procedure
Hi folks, I need to output the OrderFK from a stored procedure not really sure how to achieve this any help or tips much appreciated.
Sql code below
USE [TyreSanner]
GO
/****** Object: StoredProcedure [dbo].[AddCustomerDetails] Script Date: 11/12/2014 20:56:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddCustomerDetails]
/***********************Declare variables ***********************/
/******tblCustomer******/
@Forename nvarchar(50),
@Surname nvarchar(50),
@HouseNo nvarchar(50),
@CustAddress nvarchar(50),
@Town nvarchar(50),
@Postcode nvarchar(50),
@ContactNo nvarchar(50),
@EmailAddress nvarchar(50),
/******tblLink_OrderProduct******/
@ProductQuantity int,
@TotalProductSaleCost decimal,
@ProductFK int,
@FittingDate date,
@FittingTime Time
As
DECLARE @CustomerFK int;
DECLARE @OrderFK int;
Begin TRANSACTION
SET NOCOUNT ON
INSERT INTO [TyreSanner].[dbo].[Customer](Forename, Surname, HouseNo, CustAddress, Town, Postcode, ContactNo, EmailAddress)
VALUES (@Forename,@Surname,@HouseNo,@CustAddress,@Town,@Postcode,@ContactNo,@EmailAddress)
Set @CustomerFK = SCOPE_IDENTITY()
INSERT INTO [TyreSanner].[dbo].[Order] (CustomerFK)
VALUES (@CustomerFK)
SET @OrderFK = SCOPE_IDENTITY()
INSERT INTO [TyreSanner].[dbo].[Link_OrderProduct](OrderFK, ProductFK, ProductQuantity, TotalProductSaleCost, FittingDate, FittingTime)
VALUES
(@OrderFK, @ProductFK, @ProductQuantity, @TotalProductSaleCost, @FittingDate, @FittingTime)
COMMIT TRANSACTIONHi brucey54,
There’re several ways to capture the value from a Stored Procedure. In you scenario, I would suggest 2 options, by an output parameter or by a table variable.
By an output Parameter, you need to make a little bit modification on your code as below:
USE [TyreSanner]
GO
ALTER PROCEDURE [dbo].[AddCustomerDetails]
@Forename nvarchar(50),
@FittingDate date,
@FittingTime Time,
@OrderFK int output
As
DECLARE @CustomerFK int;
--DECLARE @OrderFK int;
Run the following code, Then @OrderFKvalue holds the value you’d like.
DECLARE @OrderFKvalue int;
EXEC AddCustomerDetails(your parameters,@OrderFKvalue output)
Anyway if you don’t like to add one more parameter, you can get the value by a table variable as well. Please append “SELECT @OrderFK;” to your Procedure as below:
USE [TyreSanner]
GO
ALTER PROCEDURE [dbo].[AddCustomerDetails]
SET @OrderFK = SCOPE_IDENTITY()
INSERT INTO [TyreSanner].[dbo].[Link_OrderProduct](OrderFK, ProductFK, ProductQuantity, TotalProductSaleCost, FittingDate, FittingTime)
VALUES
(@OrderFK, @ProductFK, @ProductQuantity, @TotalProductSaleCost, @FittingDate, @FittingTime);
SELECT @OrderFK;
Then you can call the Stored Procedure as below:
DECLARE @T TABLE (OrderFK INT);
INSERT @T EXEC AddCustomerDetails(your parameters) ;
SELECT OrderFK FROM @T;
There’re more options to achieve your requirement, please see the below link:
How to Share Data between Stored Procedures
If you have any question, feel free to let me know.
Best Regards,
Eric Zhang -
Mapping display only item to three output parameters from a procedure?
Hi all
I have a procedure with three output parameters, which I would like to map the three output parameters to three display only items on the page.
there is a page process called the procedure, which output statement1,statement2,statement3 parameters.
I have three items on the page which I would like to map them to the three parameters respectively,
how can I achieve this?
thanksRajesh,
please check if this following proposal could serve you.
Define the Query with mode FixedQueryWithOutput. In the package define a ref cursor as IN OUT parameter. To get your 3 values back, open the cursor in your procedure like "Select val1, val2, val3 from dual". Then the values should get into your query.
Here is an example how this could be defined.
Package:
type return_cur IS ref CURSOR;
Procedure:
PROCEDURE myProc(myReturnCur IN OUT return_cur) ...
OPEN myReturnCur FOR SELECT val1, val2, val3 FROM dual;
Query:
DECLARE
MYRETURNCUR myPackage.return_cur;
BEGIN
myPackage.myProc(
MYRETURNCUR => ?
END;
Good luck.
Michael -
Crystal Report with Optional Parameters from Stored Procedure
I have a client who created a Crystal Report. This report is linked to a Stored Procedure which allows for input on two criteria. Both of these critera are static values. However, the second of these parameters is setup to allow the user to enter up to 20 values. For example, the Stored Procedure needs the CARDCODE, and a set of DOCUMENTS. So the parameters/prompts would look like this...
BP CardCode:
Document1:
Document2:
Document3:
...etc...
The report will just display basic document information for those documents that were entered.
With 8.8, these parameters were changed to be REQUIRED.... not OPTIONAL. According to SAP note 1500777, this is a known bug and will be fixed in future versions. This note also states to change the criteria for the filter. However, when using a Stored Procedure, this does not appear to be an option, as the selection is defined by the data connection (and the parameters defined in the SP).
Am I missing something? Is there a way to make the suggetion in the above note work with my Stored Procedure?
Or, is there another way to make these parameters optional? (Do I need to change the SP?)
Thanks!
~ terry.I have a client who created a Crystal Report. This report is linked to a Stored Procedure which allows for input on two criteria. Both of these critera are static values. However, the second of these parameters is setup to allow the user to enter up to 20 values. For example, the Stored Procedure needs the CARDCODE, and a set of DOCUMENTS. So the parameters/prompts would look like this...
BP CardCode:
Document1:
Document2:
Document3:
...etc...
The report will just display basic document information for those documents that were entered.
With 8.8, these parameters were changed to be REQUIRED.... not OPTIONAL. According to SAP note 1500777, this is a known bug and will be fixed in future versions. This note also states to change the criteria for the filter. However, when using a Stored Procedure, this does not appear to be an option, as the selection is defined by the data connection (and the parameters defined in the SP).
Am I missing something? Is there a way to make the suggetion in the above note work with my Stored Procedure?
Or, is there another way to make these parameters optional? (Do I need to change the SP?)
Thanks!
~ terry. -
Triggers accepting parametes from stored procedures
Can triggers accept parameters from stored procedures like some filename or column name of a table and pass them to external c procedures.If so I would greatly appreciate if any one could provide me with an example.
P.S The trigger is on a view and the view which in turn should be created in the stored procedure.
Thanks
HariniHello,
Yes you can invoke Web Services from the database, it is often called "Database Web Service call out" and it is documented in the Web Services Developer Guide
Regards
Tugdual Grall -
Ora-06550 returning data from Stored Procedure and Entity Data Model
Hi.
I'm creating an application that uses a WCF Service to return data. I also created a proyect with the EDMX design and mapped most of my DBModel to a classes context. I have added some of the procedures as well. One of them receive some parameters and return a Sys_RefCursor, that is populated according to the parameters.
I have declared the "<add >" tags in the Web.Config and imported the function of the Procedure. When I call the Asyncronous function I get different exceptions:
1. If I call the function, with all of the parameters i get:
Oracle.DataAccess.Client.OracleException: ORA-06550: línea 1, columna 8:
PLS-00306: número o tipos de argumentos erróneos al llamar a
'SP_HECHOSJURITER'
ORA-06550: línea 1, columna 8:
(wrong number or types of arguments in call to 'SP_HECHOSJURITER')
2. If i just set 1 parameter in the SP, returning the same type of data, I get:
Error al recibir la respuesta HTTP a
http://localhost/Procalculo.CGFM.SIGOC.DatosServices/ServiceDatos.svc.
(failed to receive http response. error 12152)
3. If I don't set any parameters in the procedure, it works fine, and return correct data.
It exclusively happen with one entity.
Any clue?
I appreciate any help.When you return result sets from stored procedures to Entity Framework, you are very likely using implicit result sets. Implicit result sets don't need to be declared as a parameter in code, only in the <add> tags to define the metadata in the .NET config file.
For example, in the EF Oracle By Example, you'll see that the stored procedure in the function import has three parameters, but only two are declared in the code. The third one was defined in the config file.
http://download.oracle.com/oll/obe/EntityFrameworkOBE/EntityFrameworkOBE.htm -
URGENT : Return Bulk data from Stored Procedure
Hi,
Tell me, how do I return a bulk of data which
does not exist in the data base
but is concluded while the Stored Procedure is executed
from the Stored procedure
to the C++ program.
For Example:
Table ABC
Field1 Field2 Field3
A 1 3
B 1 5
C 2 10
Table DEF
Field1 Field2 Field3
D 10 24
E 3 16
F 8 19
SP_TESTING
Depending on the values in both the tables
for some range of conditions,
a conclusion X is derived for each range value of the
condition range.
Now I need to return this bulk of data X with the
condition they belong to
back to the C++ code calling it....
NOTE : A stored procedure is requited as there is a lot
of processing
required before we conclude the result X for each value
in the condition range.
If I execute this code from C++ instead of Stored
procedure
it is very slow and speed is a prime requirement of my
system.
Also i'm not using any MFC class to access database.
I'm using ConnectionPtr, RecordsetPtr and _CommandPtr
from msado15.dll for database access...
One solution to this could be use of Temp tables.
As this process is used by a lot of different stored
procedures having a common
temp table to all will need something like 50 NUMERIC
fields, 50 VARCHAR fields
and so on, which doesn't seem like a very good solution
to this problem.
Sounds like something I would have done while in school,
implement a dumb solution.
So, please suggest me a solution as to how do I return
bulk data in the form
of recordsets from stored procedure.
Regards
ShrutiUse Out parameter mode
SQL> CREATE OR REPLACE procedure a1 (x OUT NUMBER, y OUT NUMBER) AS
2 BEGIN
3 x:= 1;
4 y:= 2;
5 END;
6 .
SQL> /
Procedure created.
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 a NUMBER :=3;
3 b NUMBER :=4;
4 BEGIN
5 a1 (a,b);
6 DBMS_OUTPUT.PUT_LINE( 'a = ' || a );
7 dbms_output.put_line( 'b = ' || b );
8 END;
9 .
SQL> /
a = 1
b = 2
PL/SQL procedure successfully completed.By default parameters are copied to the OUT parameter mode .
COPY hint in PLSQL don’t send a pointer to calling program unit but NOCOPY
does.
Khurram -
Returning SQL cursor from Stored Procedure
Hi,
I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
assume both query returns equal number of rows.. however both are not related to each other..RP wrote:
Hi,
I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
assume both query returns equal number of rows.. however both are not related to each other..It sounds like what you need is a ref cursor.
First thing to remember though is that cursors do not hold any data (see: {thread:id=886365})
In it's simplest form you would be creating a procedure along these lines...
SQL> create or replace procedure get_data(p_sql in varchar2, p_rc out sys_refcursor) is
2 begin
3 open p_rc for p_sql;
4 end;
5 /
Procedure created.
SQL> var rc refcursor;
SQL> exec get_data('select empno, ename, deptno from emp', :rc);
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
14 rows selected.
SQL> exec get_data('select deptno, dname from dept', :rc);
PL/SQL procedure successfully completed.
SQL> print rc
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
50 IT SUPPORTWhich takes an SQL statement (as you said that both your queries were unrelated), and returns a ref cursor, and then your Java code would fetch the data using that cursor.
Now, as for getting your rows to columns and combining two queries that do that... something along these lines...
SQL> select * from x;
C
A
B
C
SQL> select * from y;
C
D
E
F
SQL> ed
Wrote file afiedt.buf
1 select x.col1, x.col2, x.col3
2 ,y.col1 as col4
3 ,y.col2 as col5
4 ,y.col3 as col6
5 from (
6 select max(decode(rn,1,col1)) as col1
7 ,max(decode(rn,2,col1)) as col2
8 ,max(decode(rn,3,col1)) as col3
9 from (select col1, rownum rn from (select * from x order by col1))
10 ) x
11 cross join
12 (
13 select max(decode(rn,1,col1)) as col1
14 ,max(decode(rn,2,col1)) as col2
15 ,max(decode(rn,3,col1)) as col3
16 from (select col1, rownum rn from (select * from y order by col1))
17* ) y
SQL> /
C C C C C C
A B C D E F... will do what you ask. For further information about turning rows to columns read the FAQ: {message:id=9360005} -
Help! Need oracle help with constructing stored procedure that return resultsets
Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
Thats if you build your stored procedure something like this ...
String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
(p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
is
begin
open p_cursor for
select * from suppliers
In which case the above mentioned sun code doesn't work.
We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
Thats if you build your stored procedure something like this ...
String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
(p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
is
begin
open p_cursor for
select * from suppliers
In which case the above mentioned sun code doesn't work.
We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them? -
How to get RECORD data in output parameter of stored procedure
I would like to return some data through RECORD structure from stored procedure.
I have defined the RECORD as below:
type ShipmentStatus is record(
Booked integer,
OnWater integer,
OnRoad integer,
InAir integer,
OnRail integer,
InWarehouse integer,
Idle integer);
the stored procedure is defined as
create or replace procedure SP_MC_GET_SHIPMENT_STATUS
iCustId in nvarchar2,
oResult out ShipmentStatus
I can get result in Sql*plus or PL/SQL developer, but I failed in get the result in Toplink.
How can I get the output result, and convert it to an ENTITY by Toplink?
Could you give me some advices on how to do mapping, how to call the stored procedure etc.., or code snip?
Your answer is deeply appreciated. :)I'm not sure it is possible to get the PL/SQL record type through JDBC. Please try to access this procedure through JDBC to see if it is possible.
You may need to convert the record type, to an object-type, i.e. wrap the procedure in another procedure that converts the record type. You could also just wrap the procedure in another that expands the record values into individual output parameters. -
Is it possible to pass a null Input Oracle parameter to a stored procedure
I have a stored procedure that take 3 inputs and gives 1 output.I'm using Oracle parameter to add all 3 input parameters as follows :
OracleParameter inobj = cmd.Parameters.Add("wid", OracleDbType.Int32,50);
inobj.Direction = ParameterDirection.Input;
inobj.Value = _employeeID;
and added the output parameter as follows:
OracleParameter outobj = _cmd.Parameters.Add("w_first", OracleDbType.Varchar2, 50);
outobj.Direction = ParameterDirection.Output;
On the UI end , the user has a choice to provide 1 input or all inputs or any 2 inputs based on his interest. Stored Proc looks as follows:
SP( inp1 in parameter, inp2 in parameter, inp3 in parameter, output1 out parameter)
If i just get 1 input or 2 inputs from the user, is it fine to query the data for output using same stored procedure or should i have individual stored procedures for each scenario(combination of different inputs)?
Will i get any pl/sql error that says invalid number of arguements?This means if i have 1 input , i need to have a different method to pass 1 parameter value and other input parameters as null and if there are 2 inputs will need different method to handle. So 5 different methods all together?
What if the stored procedure is as follows ,will its make things easier so that only one method is used for all scenarios?(optional parameters is set default value as null in the stored proc)
Create or Replace
Procedure GetFoo
(cur_z OUT sys_refcursor,
pub_date IN varchar2,
fname IN varchar2 default null,
lname IN varchar2 default null,
phone IN varchar2 default null
IS
BEGIN
---get some data
END;
*actually i can test this but, all the database servers are down today. So, i need to have idea if this thing works before i confirm with someone. Thanks. -
How to generate a report from stored procedure
I would like to generate a report from stored procedure.
I used to work on sql server. this can be done as easy as put a select statement at the end of stored procedure.
The resule can be displayed on the development IDE, like sql developer or consume by Java JDBC client.
is there equivalent way to do this in Oracle stored procedure?Hi,
What type of report you are looking..for.. ??
As you said that "I used to work on sql server. this can be done as easy as put a select statement at the end of stored procedure. "
When you execute it will return the result set and you will display directly on the FrontEnd.. Is my Understanding is correct Up to here.
See, In oracle you have call some custom stored procedures as you did in SQL Sever, but you have return the Results Sets, with help of Out put paramter, Either Cursors or Varrays..
or Else you can generate the Html reports based on your requirement, HTML can be used in the stored procedures of Oracle which will generate for your, you need to code it.
I could not able get the relevant link for your reference.
I will get back to you on this.
- Pavan Kumar N -
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.
Maybe you are looking for
-
I have an iPad and I bought a pre released book on iBooks. The book cover appears in my library but it won't download. Does anyone know what I should do? Mimi
-
Problem with my geforce 4 ti4200-td card
Hello all, I need some help trying to figure out what is wrong with my video card. I have a geforce 4 ti 4200-td 128 ddr ram. which I had for almost a year I think. I am not to sure of the date or if it is still under warranty. Last week I turn on my
-
A s per my business requirement, we create a sales order and according to this sales order if the material is not available in stock we want to create purchase order to the vendor for the materials which not available, How I link the sales order with
-
HELP!! Process exited with exit code 128.
Hi all, I am using JDeveloper 10G to develop a struts project. I use the struts-tiles.tld to construct the layout. <tiles:insert page="classicLayout.jsp" flush="true"> <tiles:put name="title" value="User and Assigned Role" /> <tiles:put name="header"
-
Please help. I am trying to create a link for a .pdf file. I am not sure where I am going wrong because when I test the link in ie nothing happens. However, when I preview it in ie & right click I am able to save the linked file to my desktop & open