How to include an out param of a stored proc called inside a ref cursor...????
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
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.
Try rewriting your abc proceudre as two functions, abc1 and
abc2, and rewriting your test function as a test procedure. See
if you can fill in the blanks prefaced by hyphens -- in the
following code:
CREATE OR REPLACE FUNCTION abc1
(linkid IN CHAR,
year_in IN DATE,
method_in IN CHAR)
RETURN DATE
IS
date_out DATE;
BEGIN
SELECT --
INTO date_out
FROM --
WHERE --;
--or
date_out := --;
RETURN date_out;
END abc1;
CREATE OR REPLACE FUNCTION abc2
(linkid IN CHAR,
year_in IN DATE,
method_in IN CHAR)
RETURN NUMBER
IS
average_out NUMBER;
BEGIN
SELECT AVG (--)
INTO average_out
FROM --
WHERE --
GROUP BY --;
--or
average_out := --;
RETURN average_out;
END abc2;
CREATE OR REPLACE PACKAGE zzz
AS
TYPE cursortype IS REF CURSOR;
PROCEDURE test
(temp_cur OUT cursortype);
END zzz;
CREATE OR REPLACE PACKAGE BODY zzz
AS
PROCEDURE test
(temp_cur OUT cursortype)
IS
BEGIN
OPEN temp_cur
FOR
SELECT l.linkid,
l.routenumber,
abc1 (l.linkid,
TO_DATE ('01/01/2000', 'mm/dd/yyyy'),
'2'),
abc2 (l.linkid,
TO_DATE ('01/01/2000', 'mm/dd/yyyy'),
'2')
FROM link l
WHERE l.linkid <= '010999';
END test;
END zzz;
SQL> VARIABLE g_ref REFCURSOR;
SQL> EXEC zzz.test (:g_ref);
SQL> PRINT g_ref
Similar Messages
-
How to fetch %ROWTYPE OUT param of a stored procedure from Java program?
I have a stored procedure that has IN / OUT parameter as table_name%ROWTYPE.
From a java program how can I access this ROWTYPE variable?
I tried all possible documentation and none of the explains whether or not this is supported.
My use case expect exactly 1 record from the procedure and we would prefer not to use REF CURSOR.
Is there a way to achieve this? If so, can someone help me with it by posting the sample code to achieve this?
I tried all the possible OracleTypes to register the OutParameter and they all fail.
Looks like there isn't any equivalent of %ROWTYPE in OracleTypes either.
If you need, I can post my sample procedure that uses %ROWTYPE as OUT parameter.
I really appreciate your help in this regard.
- KarthikHi,
If "returning only 1 record" the showstopper for not using Ref Cursor, you might want to reconsider because as you probably know, the ref cursor is only a pointer and requires additional step to retrieve the data.
Kuassi -
HT4436 how do I find out what I have stored in the Cloud
How do I find out what I have stored in the cloud? Also I have an update (6.1.1) for my 4S I-phone but can get it to download - even when my phone is connected to my computer. Can anyone help?
You can see some of your data by going to icloud.com from a computer and signing into your iCloud account. Other data can only be viewed on an iOS device or computer that is syncing with the account.
What do you mean when you say you can't "get it to dowload"? -
I got notification - Your Apple ID was used to sign in to FaceTime on an iPad 2 . It was not me - How do I find out who or what number was called?
hi i was wondering about how can i set up my apple id min order to get notified via email when someone is using my aplle id to find my iphone?
please help -
How to pass XMLType as parameters to Java stored procs ?
How to pass XMLType as parameters to Java stored procs ?
ORA-00932: inconsistent datatypes: expected an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class got an Oracle type that could not be converted to a java class
Java stored proc -->
CREATE or replace FUNCTION testJavaStoredProcMerge( entity xmltype,event xmltype ) RETURN VARCHAR2 AS LANGUAGE JAVA
NAME 'XDBMergeOp.merge(org.w3c.dom.Document,org.w3c.dom.Document) return java.lang.String';
PL/SQL -->
declare
theQuote VARCHAR2(50);
entity xmltype;
event xmltype;
begin
entity := xmltype('<Quote><Fields><Field1>f1</Field1></Fields></Quote>');
event := xmltype('<Quote><Fields><Field2>f2</Field2></Fields></Quote>');
theQuote := testJavaStoredProcMerge(entity,event);
dbms_output.put_line(theQuote);
end;
Java class -->
public class XDBMergeOp {
public static String merge(Document entity, Document event) throws Exception {
return ...
Thanks in advance.I think you'll need to use XMLType and then extract the DOM inside java..
create or replace package SAXLOADER
as
procedure LOAD(P_PARAMETERS XMLTYPE, P_DATASOURCE BFILE);
end;
create or replace package body SAXLOADER
as
procedure LOAD(P_PARAMETERS XMLTYPE, P_DATASOURCE BFILE)
AS
LANGUAGE JAVA
NAME 'com.oracle.st.xmldb.pm.saxLoader.SaxProcessor.saxLoader ( oracle.xdb.XMLType, oracle.sql.BFILE)';
end;
public static void saxLoader(XMLType parameterSettings, BFILE dataSource)
throws Exception {
Document parameters = parameterSettings.getDocument();
SaxProcessor app = new SaxProcessor(parameters);
app.processXMLFile(dataSource);
Edited by: mdrake on Apr 6, 2009 11:28 AM -
How to get two out param which is used in Procedure
hi experts,
Am keep on thinking, but not yet answer myself.. so am here
Using Jdev11.1.1.5.0-adfbc.
I had in db, procedure like this
PROCEDURE proc_find_x_cal_year_period
p_bu VARCHAR2,
p_date DATE,
p_year OUT NUMBER,
p_period OUT NUMBER
).................i wrote like this in My AM, Procedure is execution and printing out param values Perfect
public void ProcFindxCalYearPeriod(String pbu,
oracle.jbo.domain.Date pdate)
CallableStatement st = null;
try{
String sql = "begin proc_find_x_cal_year_period" +
"(:pbu," +
":pdate," +
":pyear," +
":pperiod)" +
";" +
"end;";
st=getDBTransaction().createCallableStatement(sql,this.getDBTransaction().DEFAULT);
st.setObject("p_bu",pbu);
st.setObject("pdate",pdate);
st.registerOutParameter("pyear",Types.VARCHAR);
st.registerOutParameter("pperiod",Types.VARCHAR);
st.execute();
System.out.println("pyear" +(String)st.getObject("pyear"));
System.out.println("pperiod" +(String)st.getObject("pperiod"));
catch(SQLException e)
throw new JboException(e);
finally
if(st!=null)
try{
st.close();
catch(SQLException e){}
}what i did/my need:
i paste this ProcFindxCalYearPeriod in my one of the Eo and while am validating one of the field,this procedure should call at the time of calling, two out parameters set into two of the corresponding setter methods.
(String)st.getObject("pyear")
(String)st.getObject("pperiod")value is here i want to set into setAttributeInternal("x",(String)st.getObject("pyear") );
setAttributeInternal("x1",(String)st.getObject("pperiod") );
i hope you all understood.In your procedure you should create an object to hold the outputs and return this object
public ProcResult ProcFindxCalYearPeriod(String pbu, oracle.jbo.domain.Date pdate)
CallableStatement st = null;
try{
String sql = "begin proc_find_x_cal_year_period" +
"(:pbu," +
":pdate," +
":pyear," +
":pperiod)" +
";" +
"end;";
st=getDBTransaction().createCallableStatement(sql,this.getDBTransaction().DEFAULT);
st.setObject("p_bu",pbu);
st.setObject("pdate",pdate);
st.registerOutParameter("pyear",Types.VARCHAR);
st.registerOutParameter("pperiod",Types.VARCHAR);
st.execute();
System.out.println("pyear" +(String)st.getObject("pyear"));
System.out.println("pperiod" +(String)st.getObject("pperiod"));
//assuming that you are getting the desired outputs
*ProcResult outputs=new ProcResult();*
*outputs.setOutParam1((String)st.getObject("pyear"));*
*outputs.setOutParam2((String)st.getObject("pperiod"));*
*return outputs;*
catch(SQLException e)
throw new JboException(e);
finally
if(st!=null)
try{
st.close();
catch(SQLException e){}
}Now you call this procedure like this
ProcResult execProc= ProcFindxCalYearPeriod(paramValue1, paramValue2);
//you can get the proc outputs by calling
String firstOutput = execProc.getOutParam1();
String second = execProc.getOutParam2();But the question is why you are calling setAttributeInternal() while you are validating an attribute?
I think this is not correct. -
Can anyone provide some insight on the problem that I am experiencing? I have an IPhone 3GS. Four of the 8 total gigs are taken up in the other category. I have attempted to delete apps numerous other things to free up space; however, I cannot determine why so much of the device's capacity is taken up in the other category. How can I find out what is stored in the other category to free up some of the device's storage capacity.
Also read this . If what i put first doesnt fix it.
https://discussions.apple.com/message/12525465#12525465 -
How to pass a refcursor to a java stored proc
Hi all,
Please forgive me as I am new to Java and JDeveloper....
I want to pass a refcursor to a java stored proc. Does anyone know how to accomplish this?
Thanks,
dayneoHi,
As Avi has indicated, you can map ref cursor to java.sql.ResultSet
here are Call Specs and a code snippet from chapter 3 in my book.
procedure rcproc(rc OUT EmpCurTyp)
as language java
name 'refcur.refcurproc(java.sql.ResultSet[])';
function rcfunc return EmpCurTyp
as language java
name 'refcur.refcurfunc() returns java.sql.ResultSet';
* Function returning a REF CURSOR
public static ResultSet refcurfunc () throws SQLException
Connection conn = null;
conn = DriverManager.getConnection("jdbc:oracle:kprb:");
((OracleConnection)conn).setCreateStatementAsRefCursor(true);
Statement stmt = conn.createStatement();
((OracleStatement)stmt).setRowPrefetch(1);
ResultSet rset = stmt.executeQuery("select * from EMP order by empno");
// fetch one row
if (rset.next())
System.out.println("Ename = " + rset.getString(2));
return rset;
Kuassi -
If adding more in-params to the stored proc degrade the performance at all?
Hi All,
I have a stored proc, currently having 18 in-params and i have to add 4 new in-params. I just want to know, if there will be any performance degradation or not?
Thanks & Regards
--DevBilly,
How can i deviate from the SW engr. concepts? I'm not from Mars. I just want to know, if there will be any perf. degradation, what is the cause behind that? What are the technical events occured inside the pl/sql compiler that degrades the performance.
--DKar -
ASAP: How a stored proc calls OS(unix)Commands
urgent!!
My stored procedure requires to call unix commands HOW DO I DO IT?
my rqrmnt is :
stored proc is :-
1.for each file in a directory($ls)
do
2.sql stmnts of insert etc
/OR
use sqlldr for the same.
done.
** how do i do both the operations 1&2 in the same Oracle procedure?I know HOST can be used in form for OS command but I never thought about doing OS command in the stored procedure.
Hmm...........
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by [email protected] ... ([email protected]):
urgent!!
My stored procedure requires to call unix commands HOW DO I DO IT?
my rqrmnt is :
stored proc is :-
1.for each file in a directory($ls)
do
2.sql stmnts of insert etc
/OR
use sqlldr for the same.
done.
** how do i do both the operations 1&2 in the same Oracle procedure?
<HR></BLOCKQUOTE>
null -
How do i handle out parameter from a stored procedure in a vb form?
hi all,
I want to return a varchar2(500) type of out parameter from a pl/sql stored procedure to a vb form?? how do i do this??
regards
akshayWell, when you create the parameter collection for your command object, just set the correct value for the direction component.
You would set it to one of the below, depending on if the parameter is IN OUT or only OUT:
<parameter_obj>.Direction = ParameterDirectionEnum.adParamInputOutput
<parameter_obj>.Direction = ParameterDirectionEnum.adParamOutput -
How to retrieve the outer parameter of a stored procedure in XSQL page
I have to call a stored procedure in the xsql page that returns a resultset (ie. oracle table/record type) through an outer paramter. Is there any built-in xsql action tag available to get the parameter and present
it in xml on the page? please help, thanks.You cant get two resultsets out of SP like this. The workaround is to merge and bring the resultsets.
For this number of columns as well as corresponding datatypes have to be compatible. Also you will need one additional column which indicates resultset value. Then use this as filter to get your desired resultset out
create procedure GetData as
begin
select 'resultset1' as Cat,*,.. N columns from Emp
union all
select 'resultset2' as Cat,*,.. N columns from Dept
end
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
Select column1,column2,column3
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset1'
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
Select column1,column2,column3, column4
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset2'
also see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
Another method is to populate table with relevant resultset within procedure itself and then select from the table directly outside.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How to pass Table name as argument in Stored Proc
Hi ,
I have a requirement wherein the table name has to be passed as an argument of SP and the output should be the count from that table based on some filter condition.
Something like this:
create or replace procedure Testing(p_table varchar2,p_count OUT integer) AS
begin
select count(1) into p_count from p_table;
end;
Getting the error on running above code:
PL/SQL: ORA-00942: table or view does not exist
Please let me know how can we do this?
Thanks.Example :SQL> create or replace procedure Testing(
2 p_table varchar2,
3 p_count OUT integer) AS
4 begin
5 execute immediate 'select count(1) from '||p_table
6 into p_count;
7 end;
8 /
Procedure created.
SQL> var n1 number;
SQL> exec Testing('user_objects',:n1);
PL/SQL procedure successfully completed.
SQL> print n1
N1
37
SQL> -
Who know how to handle pl/sql table return from stored procedure calling from jsp
I have some stored procedure which return pl/sql table (index by table), It is look like an array. how jdbc handle this?
CallableStatement cs = con.prepareCall("EXECUTE bill.getcountry(?,?)");
cs.setInt(1, cid);
cs.registerOutParameter(2, java.sql.Types.VARCHAR);// ARRAY?
ResultSet rs = cs.executeQuery();
Array array = (Array) rs.getObject (1);
ResultSet array_rset = array.getResultSet ();Not that familiar with the OCI (Oracle Call Interface), but I think this call will be problematic - the OCI deals with SQL data types and not with PL/SQL structures.
The OCI has since Oracle 8i sported an object call interface (see OCI Runtime Environment for Objects for details).
This allows you to use the CREATE TYPE command to create advance user data types - and these are supported by the SQL engine, PL/SQL engine and external languages via the OCI.
So you need to have a look at the Perl-DBI documentation to see how it supports Oracle object types and consider using these. As for internal PL/SQL data structures. These are not supported by the SQL engine and I would expect limited or no support in the OCI for these. Anyway, using SQL data types makes a lot more sense ito flexibility and transparency across languages and environments. -
How do I get return parameters from a stored procedure call?
The Open SQL Statement has an option on the Advanced tab to specify a command type of 'stored procedure'. In addition to returning a recordset, a stored procedure can also return parameters (see http://support.microsoft.com/support/kb/articles/Q185/1/25.ASP for info on doing this with ADO). Is it possible to get those return parameters with TestStand? In particular, I want to be able to get error codes back from the stored procedure in case it fails (maybe there is another way).
The Open SQL Statement step type does not fully support stored procedures. If the procedure returns a record set than you can fetch the values as you would a SELECT statement. Stored procedures require you to setup the parameters before the call and this is not yet supported. Bob, in his answer, made a reference to the Statements tab and I think that he was talking about the Database Logging feature in TS 2.0.
If the stored procedure is returning a return value, it may return as a single column, single row recordset which can be fetched as you normally do a record set.
Scott Richardson
National Instruments
Maybe you are looking for
-
Xf86-video-intel doesnt like my 945GME
I run Archlinux on an HP mini 1000 and have been having problems with anything and everything graphical. Namely, even 2d games lag. I get 6fps in super mario chronicles using smc -d game performance I get 132fps from glxgears, I do realised this is n
-
HI, I want to combine the sales order and the subsequent delivery free of charge in one delivery for one customer so he receives both the goods in one single outbound delivery. KIndly reply
-
ive got a serious issue with illustrator,if anyone can pls assist me it would be great so i can solve this problem once and for all! no matter on what pc i use illustrator and i do various designs using alot of gradients and i mean alot of gradients,
-
German umlauts in dialogue windows
I installed Framemaker 8.0.4 on Solaris. When I enter german umlauts (or french accents) in any text field of any dialogue window, Framemaker does not echo the umlaut, but a character sequence, e.g. '%X8A', instead of an 'ä' character. This is a bit
-
Need help getting scrollbar from design to code
First off id like to say I'm VERY NEW to coding I know the basics of CSS and I even less of flash. But im willing to learn anything iv only been doing this for 3 months. i have CS5 master colection ok Here is my design for the cliant's site the part