IN,OUT and IN OUT Parameter Types
Dear All,
as per some book,
IN parameter uses Call by Reference
and OUT and IN OUT Uses Call by Value
we can use NOCOPY for Making OUT and IN OUT Call by Reference.
my small doubt is
when u r passing a reference of a Variable how oracle takes care that only IN Parameter are not allowed to change (in c and c++ we can say *para to access the variables) ,
i mean in case i use NOCOPY all parameter type are using CALL BY REFERENCE then how the "No Modify" is forced in case of IN Parameter.
Thanks for Reading Request.
Raj.
The pl/sql compiler will simply not allow you to have a stmt that assigns something to an "IN" parameter. It can fully be enforced at compile time.
Tom Best
Similar Messages
-
Callable statement: out parameter type issue
Hello again.
My question is:
how can I register the out parameter of a callable statement so that it may contain an oracle Cursor?
Whether I register it to Types.OTHER (Types from the java.sql package) or OracleTypes.CURSOR (OracleTypes from the oracle.jdbc.driver package) it still says :
PLS-00382: expression is of wrong type
when trying to execute a statement that returns a cursor.
I am using the com.sap.portals.jdbc.oracle package for the driver and such.
If I change to use the oracle.jdbc.driver.OracleDriver and register the out parameter to OracleTypes.CURSOR, then it works.
Thanks in advance,
Silviu Lipovan Oanca
Message was edited by: Silviu Lipovan Oancamore detailed
1) i have write some java code using as usual my IDE:
public class P141_JAVABridge
public static void execute()
String databaseDriver = "oracle.jdbc.driver.OracleDriver";
String databaseUrl = "jdbc:oracle:thin:@xxx:1521:orcl";
String databaseUsername = "xxx";
String databasePassword = "xxx";
ods.setDriverType(databaseDriver);
ods.setURL(databaseUrl);
ods.setUser(databaseUsername);
ods.setPassword(databasePassword);
connection = ods.getConnection();
.... some code
map.put("custom_T",Custom_T_SQLData.class);
CallableStatement call = connection.prepareCall("call P141(?,?)");
call.setObject(1,inputObjectReference);
call.registerOutParameter(2,OracleTypes.STRUCT,"custom_T");
call.execute();
.... some code
2) i run this code - wooha! it works
3) i have changed
connection = ods.getConnection();
to
connection = DriverManager.getConnection("jdbc:default:connection:");
4) compile and load class into oracle
5) i have linked P141_JAVABridge.execute() with P141_JB
create or replace PROCEDURE P141_JB () IS LANGUAGE JAVA NAME 'x.y.z.P141_JAVABridge.execute()';
6) then i executed P141_JB
SET SERVEROUTPUT ON;
BEGIN
...some code
P141_JB();
...some code
END;
and got NullPointerException at
((Custom_T_SQLData)call.getObject(2)).responseStatus -
Oracle Instant Client and OUT Parameter of custom type in Stored Procedures
Hi @ all!
I try to set up a simple client application, that calls a stored procedure via Instant Client from C#.
The stored procedure and assiciated types looks like this:
TYPE MYVALUE AS OBJECT
Id INTEGER,
value FLOAT
TYPE MYVALUELIST AS TABLE OF MYVALUE;
PROCEDURE ReadValues( ID IN INTEGER,
RESULTSET OUT MYVALUELIST)
IS
...I created an Oracle Command executing this SP and added OracleParameters for ID and (where I got stuck) the RESULTSET.
Is it possible to pass a parameter with a custom type from C# in some way?
I already tried it as a function with SELECT * FROM TABLE(ReadValues(1));
With my parameter RESULTSET as the RETURN type. But since I use DML within the procedure, this does not work inside of a query...
Any suggestions?
Thanks in advance!Hi Greg!
Sorry, I misunderstood the forum topic then. =(
Anyway, in the example you provided in the link, this is nearly exactly my situation. But there the Oracle.DataAccess.Client is used, where the OracleDBType can be called to initialize an object of type person. I use the instant client libraries called by using System.Data.OracleClient. There is only the OracleType enum, that does not contain an object or something similar.
So I do it right now after trying a bit with a ref cursor parameter and an OracleDataAdapter - the ref cursor is passed back from Oracle as a DataReader, so die DataAdapter is able to use it for a .Fill():
OracleCommand cmd = new OracleCommand();
cmd.Parameters.Add("RESULTSET", OracleType.Cursor).Direction = ParameterDirection.Output;
OracleDataAdapter odr = new OracleDataAdapter(cmd);
DataTable result = new DataTable();
odr.Fill(result);Within my stored procedure I just added the following OUT parameter:
PROCEDURE ReadValues( ID IN INTEGER,
RESULTSET OUT sys_refcursor)
IS
currentlist MYVALUELIST;
... [Adding elements to that list] ...
OPEN resultset for select * from TABLE(currentlist);It works now, but I don't like that solution that much since I'm always afraid that there are lots of opened cursors idyling around. Do I have to close this one explicitly after filling my table by the DataAdapter?
Regards -
Performance problem with sproc and out parameter ref cursor
Hi
I have sproc with Ref Cursor as an OUT parameter.
It is extremely slow looping over the ResultSet (does it record by record in the fetch).
so I have added setPrefetchRowCount(100) and setPrefetchMemorySize(6000)
pseudo code below:
string sqlSmt = "BEGIN get_tick_data( :v1 , :v2); END;";
Statement* s = connection->createStatement(sqlStmt);
s->setString(1, i1);
// cursor ( f1 , f2, f3 , f4 , i1 ) f for float type and i for interger value.
// 5 columns as part of cursor with 4 columns are having float value and
// 1 column is having int value assuming 40 bytes for one rec.
s->setPrefetchRowCount (100);
s->PrefetchMemorySize(6000);
s->registerOutParam(2,OCCICURSOR);
s->execute();
ResultSet* rs = s->getCursor(2);
while (rs->next()) {
// do, and do v slowly!
}Hi,
I have the same problem. It seems, when retrieving cursor, that "setPrefetchRowCount" is not taking into account by OCCI. If you have a SQL statement like "SELECT STR1, STR2, STR3 FROM TABLE1" that works fine but if your SQL statement is a call to a stored procedure returning a cursor each row fetching need a roudtrip.
To avoid this problem you need to use the method "setDataBuffer" from the object "ResultSet" for each column of your cursor. It's easy to use with INT type and STRING type, a lit bit more complex with DATE type. But until now, I'm not able to do the same thing with REF type.
Below a sample with STRING TYPE (It's assuming that the cursor return only one column of STRING type):
try
l_Statement = m_Connection->createStatement("BEGIN :1 := PACKAGE1.GetCursor1(:2); END;");
l_Statement->registerOutParam(1, oracle::occi::OCCINUMBER, sizeof(l_CodeErreur));
l_Statement->registerOutParam(2, oracle::occi::OCCICURSOR);
l_Statement->executeQuery();
l_CodeErreur = l_Statement->getNumber(1);
if ((int) l_CodeErreur == 0)
char l_ArrayName[5][256];
ub2 l_ArrayNameSize[5];
l_ResultSet = l_Statement->getCursor(2);
l_ResultSet->setDataBuffer(1, l_ArrayName, OCCI_SQLT_STR, sizeof(l_ArrayName[0]), l_ArrayNameSize, NULL, NULL);
while (l_ResultSet->next(5))
for (int i = 0; i < l_ResultSet->getNumArrayRows(); i++)
l_Name = CString(l_ArrayName);
l_Statement->closeResultSet(l_ResultSet);
m_Connection->terminateStatement(l_Statement);
catch (SQLException &p_SQLException)
I hope that sample help you.
Regards -
Calling a stored procedure with a table of custom types as a out parameter
Hi,
I'm trying to use toplink 11.1.1.0.0 to call a stored procudure with 4 in paramrs and a single out parameter of type gsearch_type which is a userdefined type defined as below
CREATE or replace TYPE search_object as object (mdlnumber varchar2(12), hit clob);
create or replace type gsearch_type as table of search_object;
Is it possible to get the return value from this stored procedure using toplink.
Thanks in advance for any help.
- SunilCurrently TopLink can't directly handle that kind of output parameter.
As a workaround you would need a wrapper for the stored procedure - it could be either another stored procedure or an anonymous block which would return the components of the complex parameter as several simple parameters. -
Problem in Mapping RefCursors(in/out parameter) and Collections(in/out)
Hi,
Can anyone help to solve the proble listed below as it is affecting the business process
The API for A is listed below. It takes Oracle Object types as input/output.
PROCEDURE A(
p_serviceOrder IN ServiceOrder,
p_serviceID IN OUT p_sm_type.ServiceID,
p_serviceOrderID OUT p_sm_type.ServiceOrderID,
returnStatus OUT CallStatus);
The ServiceOrder and CallStatus are Oracle Object types.
The wrapper procedure for this api would be something like the example with pseudo-code below.
PROCEDURE B(
p_serviceOrder IN REF CURSOR,
p_serviceID IN OUT p_sm_type.ServiceID,
p_serviceOrderID OUT p_sm_type.ServiceOrderID,
returnStatus OUT REF CURSOR) {
Map from REF CURSOR p_serviceOrder To Oracle Object for ServiceOrder;
Map from other data types to local variables;
Call A(pass the parameters here and get output );
Map output CallStatus to its equivalent REF CURSOR variable;
Return CallStatus (and other OUT parameters if any) as REF CURSORs;
It will be highly needful for the solution as it is affecting the business flow requirement.
Regards
SaugataHi,
i think you must set the value for this parameter and additional you must
register this parameter as out parameter.
I hope it works. -
Calling an Oracle stored procedure and retrieving result from OUT parameter
Hello,
I have a stored procedure that returns a string in an OUT parameter after receiving 6 IN parameters. I have tested the procedure in PL/SQL and it's producing the right output there. The problem is when I call the stored procedure from my Java method. I then get an error message telling me that I have the wrong number or types of arguments in my procedure call. I have checked that the method receives and sends the correct data in the correct order and I'm not sure what else the error message can relate to...?
The exception is called on my second try statement but I haven't been able to find out what I have done wrong there. Does anyone have any suggestions? Thanks.
the error message
java.sql.SQLException: ORA-06550: line 1, column 13: PLS-00306: wrong number or types of arguments in call to 'P_SET_GIVEN_ANSWER' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
the procedure
CREATE OR REPLACE PROCEDURE p_set_given_answer(
strfeedback OUT VARCHAR2,
intpi_id IN INTEGER,
intquestion_id IN INTEGER,
intgivenanswer IN INTEGER,
strgivenprefix IN VARCHAR2,
strgivenunit IN VARCHAR2,
strgu_id IN VARCHAR2) AS
-- some declarations
BEGIN
-- some processing and then returns the string below indicating the outcome
strfeedback = 'result';
END
the java method (the class is called dbUtil and the database connection is created in the method called getDbConnection() )
public void setGivenAnswer(int intPi_id, int intQuestion_id, int intGivenAnswer, String strGu_id, String strGivenPrefix, String strGivenUnit) {
java.sql.Connection con = null;
String query = "{call ? := p_set_given_answer(?,?,?,?,?,?)}";
try {
con = dbUtil.getDbConnection();
} catch(Exception e) {
dbConnectionExceptionMessage = "error 1:"+e.toString();
try{
CallableStatement stmt = con.prepareCall(query);
// register the type of the out param - an Oracle specific type
stmt.registerOutParameter(1, OracleTypes.VARCHAR);
// set the in params
stmt.setInt(2, intPi_id);
stmt.setInt(3, intQuestion_id);
stmt.setInt(4, intGivenAnswer);
stmt.setString(5, strGivenPrefix);
stmt.setString(6, strGivenUnit);
stmt.setString(7, strGu_id);
// execute the stored procedure
stmt.execute();
// retrieve the results
strFeedback = stmt.getString(1);
} catch (java.sql.SQLException e) {
dbConnectionExceptionMessage = "error 2:"+e.toString();
try {
con.close();
} catch (java.sql.SQLException e) {
dbConnectionExceptionMessage = "error 3:"+e.toString();
----------------------------------------Looks like you are declaring a procedure, but you are calling it like a function. A procedure has no return value, it has only parameters: "{call p_set_given_answer(?,?,?,?,?,?,?)}"
-
Procedure with table type out parameter
Hi,
I need to create a procedure which gives back a content of a table as an out parameter.
i have tried something like below code
it might not be correct since i am writing from home and cannot access any oracle db right now
create or replace procedure test (
table_out test_table%rowtype
) as
type table_out test_table%rowtype
begin
select * into table_out
from test_table
where country = 'HUN';
end;
compile doesnt gives error, but when running it i get error
declare
table_out test_table%rowtype
begin
test( table_out );
dbms_output.put_line( table_out );
end;
but it fails, could you help how to solve the above problem and call the proc correctly?
thanks in advanceWell you said you want the content of a table but your example says you just want a record. So for a record:
CREATE OR REPLACE PROCEDURE sp_test (EMP_REC OUT EMP%ROWTYPE) IS
BEGIN
select * into emp_rec from emp where empno = 7369;
END;The anonymous block to run it might be:
declare
tab_out emp%rowtype;
begin
sp_test(tab_out);
dbms_output.put_line(tab_out.ename);
end;As damorgan said the dbms_output can't be used with the record type. Notice I used it for the ENAME value of the record.
If you really want the entire table then do it the way damorgan suggests. A pipeline function can give you the table but not as an OUT parameter. -
Package with table data type as out parameter.
Hi there, I managed to compile the package without error but when I am trying to test this package and
I am keep facing this error message.
Am I using correctly for the table data type as out parameter. I have no idea what is wrong with the package to fix.
Pls. help and advise me. Thanks.
Error starting at line 1 in command:
DECLARE
p_stmodel VARCHAR2(40):=null;
p_item_number VARCHAR(40):='9BX158-300';
p_item_id NUMBER:=0;
l_attribute_out test_common_api.l_item_attr_tab:=test_common_api.l_item_attr_tab();
BEGIN
test_common_api.test_attribute(p_stmodel,p_item_number,p_item_id,l_attribute_out);
END;
Error report:
ORA-06550: line 8, column 18:
PLS-00302: component 'TEST_ATTRIBUTE' must be declared
ORA-06550: line 8, column 2:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
---------Package.
CREATE OR REPLACE PACKAGE test_common_api
AS
TYPE item_attr_rec IS RECORD (CONFIGURATION VARCHAR2(20),
PRODUCTTYPE VARCHAR2(30),
INTERNALPRODUCTNAME VARCHAR2(20),
NUMBEROFHEADS VARCHAR2(2),
NUMBEROFDISCS VARCHAR2(2),
GENERATION VARCHAR2(10),
FACTORYAPPLICATION VARCHAR2(150),
PRODUCTFAMILY VARCHAR2(60),
FORMFACTOR VARCHAR2(10),
FORMATTEDCAPACITY NUMBER,
FORMATTEDCAPACITY_UOM VARCHAR2(20),
INTERFACE VARCHAR2(30),
SPINDLESPEEDRPM NUMBER,
PRODUCTCACHE VARCHAR2(10),
WARRANTYMONTHS VARCHAR2(2),
PHYSICAL_SECTOR_SIZE NUMBER,
MODELHEIGHT VARCHAR2(10),
ENCRYPTION_TYPE VARCHAR2(40));
TYPE l_item_attr_tab IS TABLE OF item_attr_rec;
END test_common_api;
show errors
create or replace package body test_common_api
AS
PROCEDURE test_attribute (p_stmodel IN VARCHAR2,
p_item_number IN VARCHAR2,
p_item_id IN NUMBER,
l_item_attr_list OUT l_item_attr_tab)
IS
l_stmodel st.stmodelnumber%TYPE;
l_market_segment VARCHAR2(10) ;
l_sub_market_segment VARCHAR2(10) ;
l_app_segment VARCHAR2(10);
l_market_name VARCHAR2(40) ;
l_ccitem seaeng_ccitemnumber.ccitemnumber%TYPE;
l_query_item VARCHAR2(1000);
l_query_model VARCHAR2(1000);
l_where VARCHAR2(1000);
l_bind_var1 VARCHAR2(40);
l_bind_var2 VARCHAR2(40);
l_sql NUMBER:=0;
l_config VARCHAR2(40):=null;
BEGIN
IF p_stmodel is not null THEN
l_where :='WHERE sc.ccmodel = sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber
AND sc.pricingdescriptor=''MODEL''
AND sc.ccdashnumber =''000''
AND sp.detailedproductname=''GENERIC''
AND st.stmodelnumber= :1';
IF p_item_number is null AND p_item_id is null THEN
l_config :='null';
ELSE
l_config :='sc.configuration';
END IF;
l_bind_var1 :=p_stmodel;
l_sql :=1;
ELSE
IF p_item_id is null and p_item_number is not null THEN
l_where := 'WHERE sc.ccmodel = sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber and sc.ccitemnumber = :1';
l_bind_var1 :=p_item_number;
l_sql:=2;
ELSIF p_item_id is NOT null and p_item_number is null THEN
l_where := 'WHERE sc.ccmodel= sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber and sc.ccitemnumber in ( select msi.segment1
from mtl_system_items msi
where msi.inventory_item_id = :1)';
l_bind_var1 := p_item_id;
l_sql:=2;
ELSIF p_item_id is not null and p_item_number is not null THEN
l_where :='WHERE sc.ccmodel = sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber and sc.ccitemnumber in (select msi.segment1
from mtl_system_items msi
where msi.inventory_item_id = :1
AND msi.segment1=:2)';
l_sql:=3;
l_bind_var1 := p_item_id ;
l_bind_var2 :=p_item_number;
END IF;
END IF;
l_query_item :='SELECT sc.configuration,st.producttype, sp.internalproductname, sp.numberofheads , sp.numberofdiscs,
sp.generation,sp.factoryapplication, st.productfamily,st.formfactor , st.formattedcapacity , st.formattedcapacity_uom,
st.interface,st.spindlespeedrpm,st.productcache,st.warrantymonths, st.physical_sector_size, st.modelheight, st.encryption_type
FROM pm sp , st st, seaeng_ccitemnumber sc ';
l_query_model :='SELECT '|| l_config|| ' , st.producttype, null,null , null, null, sp.factoryapplication, null,st.formfactor, st.formattedcapacity,
st.formattedcapacity_uom,st.interface , st.spindlespeedrpm, st.productcache, st.warrantymonths,st.physical_sector_size, st.modelheight,
st.encryption_type
FROM pm sp , st st, seaeng_ccitemnumber sc ';
IF l_sql = 1 THEN
EXECUTE IMMEDIATE l_query_model ||l_where
BULK COLLECT INTO l_item_attr_list
USING l_bind_var1 ;
dbms_output.put_line(l_query_model||l_where);
ELSIF
l_sql =2 THEN
EXECUTE IMMEDIATE l_query_item || l_where
BULK COLLECT INTO l_item_attr_list
using l_bind_var1;
dbms_output.put_line(l_query_item||l_where);
ELSE
EXECUTE IMMEDIATE l_query_item ||l_where
BULK COLLECT INTO l_item_attr_list
USING l_bind_var1, l_bind_var2 ;
dbms_output.put_line(l_query_item||l_where);
END IF;
END test_attribute;
END test_common_api;
show errorsI think you forget to declare "PROCEDURE test_attribute" procedure in your package definition. like:
CREATE OR REPLACE PACKAGE test_common_api
AS
TYPE item_attr_rec IS RECORD (CONFIGURATION VARCHAR2(20),
PRODUCTTYPE VARCHAR2(30),
INTERNALPRODUCTNAME VARCHAR2(20),
NUMBEROFHEADS VARCHAR2(2),
NUMBEROFDISCS VARCHAR2(2),
GENERATION VARCHAR2(10),
FACTORYAPPLICATION VARCHAR2(150),
PRODUCTFAMILY VARCHAR2(60),
FORMFACTOR VARCHAR2(10),
FORMATTEDCAPACITY NUMBER,
FORMATTEDCAPACITY_UOM VARCHAR2(20),
INTERFACE VARCHAR2(30),
SPINDLESPEEDRPM NUMBER,
PRODUCTCACHE VARCHAR2(10),
WARRANTYMONTHS VARCHAR2(2),
PHYSICAL_SECTOR_SIZE NUMBER,
MODELHEIGHT VARCHAR2(10),
ENCRYPTION_TYPE VARCHAR2(40));
PROCEDURE test_attribute (p_stmodel IN VARCHAR2,
p_item_number IN VARCHAR2,
p_item_id IN NUMBER,
l_item_attr_list OUT l_item_attr_tab);
TYPE l_item_attr_tab IS TABLE OF item_attr_rec;
END test_common_api;
show errors
create or replace package body test_common_api
AS
PROCEDURE test_attribute (p_stmodel IN VARCHAR2,
p_item_number IN VARCHAR2,
p_item_id IN NUMBER,
l_item_attr_list OUT l_item_attr_tab)
IS
l_stmodel st.stmodelnumber%TYPE;
l_market_segment VARCHAR2(10) ;
l_sub_market_segment VARCHAR2(10) ;
l_app_segment VARCHAR2(10);
l_market_name VARCHAR2(40) ;
l_ccitem seaeng_ccitemnumber.ccitemnumber%TYPE;
l_query_item VARCHAR2(1000);
l_query_model VARCHAR2(1000);
l_where VARCHAR2(1000);
l_bind_var1 VARCHAR2(40);
l_bind_var2 VARCHAR2(40);
l_sql NUMBER:=0;
l_config VARCHAR2(40):=null;
BEGIN
IF p_stmodel is not null THEN
l_where :='WHERE sc.ccmodel = sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber
AND sc.pricingdescriptor=''MODEL''
AND sc.ccdashnumber =''000''
AND sp.detailedproductname=''GENERIC''
AND st.stmodelnumber= :1';
IF p_item_number is null AND p_item_id is null THEN
l_config :='null';
ELSE
l_config :='sc.configuration';
END IF;
l_bind_var1 :=p_stmodel;
l_sql :=1;
ELSE
IF p_item_id is null and p_item_number is not null THEN
l_where := 'WHERE sc.ccmodel = sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber and sc.ccitemnumber = :1';
l_bind_var1 :=p_item_number;
l_sql:=2;
ELSIF p_item_id is NOT null and p_item_number is null THEN
l_where := 'WHERE sc.ccmodel= sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber and sc.ccitemnumber in ( select msi.segment1
from mtl_system_items msi
where msi.inventory_item_id = :1)';
l_bind_var1 := p_item_id;
l_sql:=2;
ELSIF p_item_id is not null and p_item_number is not null THEN
l_where :='WHERE sc.ccmodel = sp.productmodelnumber AND sp.stmodelnumber = st.stmodelnumber and sc.ccitemnumber in (select msi.segment1
from mtl_system_items msi
where msi.inventory_item_id = :1
AND msi.segment1=:2)';
l_sql:=3;
l_bind_var1 := p_item_id ;
l_bind_var2 :=p_item_number;
END IF;
END IF;
l_query_item :='SELECT sc.configuration,st.producttype, sp.internalproductname, sp.numberofheads , sp.numberofdiscs,
sp.generation,sp.factoryapplication, st.productfamily,st.formfactor , st.formattedcapacity , st.formattedcapacity_uom,
st.interface,st.spindlespeedrpm,st.productcache,st.warrantymonths, st.physical_sector_size, st.modelheight, st.encryption_type
FROM pm sp , st st, seaeng_ccitemnumber sc ';
l_query_model :='SELECT '|| l_config|| ' , st.producttype, null,null , null, null, sp.factoryapplication, null,st.formfactor, st.formattedcapacity,
st.formattedcapacity_uom,st.interface , st.spindlespeedrpm, st.productcache, st.warrantymonths,st.physical_sector_size, st.modelheight,
st.encryption_type
FROM pm sp , st st, seaeng_ccitemnumber sc ';
IF l_sql = 1 THEN
EXECUTE IMMEDIATE l_query_model ||l_where
BULK COLLECT INTO l_item_attr_list
USING l_bind_var1 ;
dbms_output.put_line(l_query_model||l_where);
ELSIF
l_sql =2 THEN
EXECUTE IMMEDIATE l_query_item || l_where
BULK COLLECT INTO l_item_attr_list
using l_bind_var1;
dbms_output.put_line(l_query_item||l_where);
ELSE
EXECUTE IMMEDIATE l_query_item ||l_where
BULK COLLECT INTO l_item_attr_list
USING l_bind_var1, l_bind_var2 ;
dbms_output.put_line(l_query_item||l_where);
END IF;
END test_attribute;
END test_common_api;
show errors -
Pass a record type vaiable in out parameter of a function in a package
Hi All,
1.I have created a ecod inside a package.
2.Then created a function which has a out parameter of the above record.
3.Now package body i'm creating a dynamic cursor .
4.My equirement is to fetch this dynamic cursor's value into the out parameter of the function.
I have created the below code for 1,2 and 3 but not getting how to achive the point 4.
create package pkg
type t_rec is recod (id number,id_name varchar2(10));
type t_data is table of t_rec index by binary_integer;
act_data t_data;
funcion return_data is (dept in number,region in number,o_rec out t_data) return boolean;
end pkg;
create package body pkg
funcion return_data is (dept in number,region in number,o_rec out t_data) return boolean is
p_cur sys_refcursor;
l_text varchar2(100);
begin
-- As per my requirement i have built a dynamic l_text which contains where clause by taking dept and region values.In actual i have nearly 10 in paramaters with >which i'm building a dynamic where clause in l_text. So i'm using a ref cursor.
open p_cur for 'select id,id_name from tab1'||l_text';
fetch p_cur bulk collect into act_data;
exception ....
end pkg;Now as per the code snippet i could fetch all the rows returned by p_cur into act_data.
But how i will pass it though out parameter in the function which i will use somewhere in front end to show data.
Please help me in this.
Thanks in advance.bp wrote:
i need to create the where clause one the basis of the values of IN parameters.Sometimes i need to take count of the data on the basis of the IN parameters and if one of the conditions return value i will build where clause with those parameters.Please google and read up on the importance of creating shareable SQL - which needs to be done using bind variables.
The ref cursor interface in PL/SQL only support a static/fixed number of bind variables. So if you want to create cursors with variable number of bind values, you need to use conditional processing. E.g.
SQL> create or replace procedure EmpFilter( c OUT sys_refcursor, nameFilter varchar2, jobFilter varchar2 ) is
2 sqlSelect varchar2(32767);
3 begin
4 --// we pretend to built a dynamic SQL statement - so the table
5 --// name and so on is "unknown"
6 sqlSelect := 'select * from emp ';
7 case
8 when nameFilter is null and jobFilter is null then
9 open c for sqlSelect;
10
11 when nameFilter is null and jobFilter is not null then
12 sqlSelect := sqlSelect||'where job like :filter';
13 open c for sqlSelect using jobFilter;
14
15 when nameFilter is not null and jobFilter is null then
16 sqlSelect := sqlSelect||'where ename like :filter';
17 open c for sqlSelect using nameFilter;
18
19 when nameFilter is not null and jobFilter is not null then
20 sqlSelect := sqlSelect||'where ename like :filter1 and job like :filter2';
21 open c for sqlSelect using nameFilter, jobFilter;
22
23 end case;
24
25 DBMS_OUTPUT.put_line( 'Dynamic SQL: '||sqlSelect );
26 end;
27 /
Procedure created.
SQL>
SQL>
SQL> var c refcursor
SQL> begin
2 EmpFilter( :c, 'A%', null );
3 end;
4 /
Dynamic SQL: select * from emp where ename like :filter
PL/SQL procedure successfully completed.
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30
7876 ADAMS CLERK 7788 1987/05/23 00:00:00 1100 20
SQL>
SQL> begin
2 EmpFilter( :c, null, 'ANALYST' );
3 end;
4 /
Dynamic SQL: select * from emp where job like :filter
PL/SQL procedure successfully completed.
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7788 SCOTT ANALYST 7566 1987/04/19 00:00:00 3000 20
7902 FORD ANALYST 7566 1981/12/03 00:00:00 3000 20
SQL>And this approach is for external clients - where a Visual Basic or Java client program calls the database, executes the stored procedure, and receives a cursor handle in turn. And the client then fetches the output of this cursor and process it.
There is no need to return a record type of any sorts. The client wants the cursor handle as that is the optimal and best interface for the client to receive database data.
If the caller is not an external client, but another PL/SQL procedure, then this approach does not make much sense.
It is important that you understand basic Oracle concepts and fundamentals. What a cursor is. What the best way is to process Oracle data. How to best use the basic features of Oracle. Without that basic understanding, you as good as a low hour Cessna pilot getting into an Airbus A400M - where the Cessna pilot would not even be able to start a single engine, never mind get the plane in the air.
Likewise, without a basic understanding of Oracle cursors and fundamentals, you will be unable to code even a single line of sensible code. Not because you are a bad programmer. Even the best programmer in the world will be unable to write decent code, if the programmer has no idea how the environment works, what the concepts and fundamentals are. But it is fair to expect that a good programmer will no write such code, understand that there is a lack of knowledge, and address that accordingly. -
How to handle the procedure that reutrn object types as out parameter
I have a procedure where it returns object(CREATE OR REPLACE TYPE xyz AS OBJECT) as a OUT parameter.
Now i have to pull the data from this type and need to send the data in excel.
Procedure will fetch data and assign it to object with lot of validations and local parameters variables..
How can i push the data from the out parameter and need to send that in excel..Its an oracle database 10g..here's a basic example...
SQL> set serveroutput on;
SQL> create or replace type t_obj as object (x number, y number);
2 /
Type created.
SQL> ed
Wrote file afiedt.buf
1 create or replace package mypkg as
2 procedure testit(p_obj out t_obj);
3 procedure callme;
4* end;
5 /
Package created.
SQL> ed
Wrote file afiedt.buf
1 create or replace package body mypkg as
2 procedure testit(p_obj out t_obj) is
3 begin
4 p_obj := t_obj(1,2);
5 end;
6 procedure callme is
7 v_obj t_obj;
8 begin
9 testit(v_obj);
10 dbms_output.put_line('X='||v_obj.x||' Y='||v_obj.y);
11 end;
12* end;
SQL> /
Package body created.
SQL> exec mypkg.callme;
X=1 Y=2
PL/SQL procedure successfully completed.
SQL> -
OUT parameter with NOCOPY hint of type SYS_REFCURSOR
Hi,
I am having a procedure which returns a set of 100+ records (each record having 10+ columns) through a OUT parameter of type SYS_REFCURSOR.
These output records are used in JAVA code for fecthing the resultset and process data.
Will it make any difference in performance if I use NOPCOPY compiler hint in this procedure (especially I am interested in the interaction between JAVA and PLSQL, with and without NOCOPY parameter).
Thanks.
Edited by: user2946813 on Mar 25, 2012 9:15 PMuser2946813 wrote:
Hi RP,
Thanks for the answer.
So the PLSQL OUT parameter of type SYS_REFCURSOR would be passing just a reference (memory address) to JAVA.
This behavior is same with or without NOCOPY. Is my understanding correct?
Thanks.Yes. A ref cursor is just a pointer to a query, not a result set of data. Using NOCOPY or not is pointless (excuse the pun) because, no matter how much data is going to get returned, the pointer itself is no smaller or larger in size, and thus using NOCOPY won't improve performance or save resources.
{thread:id=886365} -
Hi i want to use boolean type in a procedure as out parameter !!
Hi
I need to use Boolean type as out parameter in my procedure which return true if the SELECT query in procedure returns any row otherwise it should return false
please HELP !!I need to use Boolean type as out parameter in my procedure which return true if the SELECT query in procedure returns any row otherwise it should return false
Sounds like basic PL/SQL stuff.
What problem are you experiencing?
Are you looking for something like this?
create or replace procedure check_emp (p_empno in number, p_result out boolean) is
dummy pls_integer;
begin
select 1
into dummy
from scott.emp
where empno = p_empno;
p_result := true;
exception
when no_data_found then
p_result := false;
end;
SQL> declare
2 emp_exists boolean;
3 begin
4 check_emp(7839, emp_exists);
5 if emp_exists then
6 dbms_output.put_line('Employee exists');
7 else
8 dbms_output.put_line('Employee does not exist');
9 end if;
10 end;
11 /
Employee exists
PL/SQL procedure successfully completed -
Stored procedure with IN and OUT parameter
HI all,
here is code example
declare
in_dt date := '1-feb-2010' ;
col1 ...;
col2 ...;
col3 ...;
begin
select e.*
into col1,
col2,
col3
from table_xyz e
where e.start_dt = in_dt;
end;
How do i convert the above code into stored procedure by accepting "in_dt" as IN parameter and getting the result set displayed (output) through OUT parameter say "cur_out" (OUT paramter)
Thank you so much !!! I really appriciate it !!i ran my procedure which is very similar syndra posted
create or replace procedure foo(p_dt in date, cv out sys_refcursor) as
begin
open cv for
select e.*
from table_xyz e
where start_dt = p_dt;
end;
/Here is how is executed
DECLARE
P_DT DATE;
CV SYS_REFCURSOR;
BEGIN
P_DT := '10-oct-2005';
-- CV := NULL; Modify the code to initialize this parameter
scott.foo ( P_DT, CV );
COMMIT;
END;
-- i get PL/SQL procedure successfully complted , But i dont see the result set Or output
- How do i see the output when i m using refcursor ?? i tried using print , but nothing didnt work
- Any idea ??
Thank you!!
Edited by: user642297 on Jun 24, 2010 1:35 PM -
hey there, my ipad had a dialogue box pop up on the screen and the buttons are not working so i cant exit out or type. PLease help me
Perform a Reset... Reset ( No Data will be Lost )
Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
Wait for the Apple logo to Appear...
Usually takes about 15 - 20 Seconds... ( But can take Longer...)
Release the Buttons...
Maybe you are looking for
-
Site Studio Content in a Java Class
Hi Gurus, I would like to know if there's some Webcenter Content Service ou some Webcenter Portal interface, service, class ou data control to consume the content from a Site Studio Contributor Data File in my custom Java class. Obviously I can reque
-
Automator to change Exposé and Dashboard settings?
Hello, I play a couple of games that only run properly under Classic. Difficulties can arise when running games in classic as I have exposé set to use hot corners. Things can end up a bit messy! In my real life when I'm working in OS X, I really depe
-
ADF Faces refresh conditions cause NullPointerException
We are developping an ADF faces web application. For the jspx pages we use EJB3 data controls to display data from the database and other legacy systems. Most values in our application are read-only and some take some time to be provided by the datab
-
Custom bean on Approve in Human Task Form
Hi, I have a complex requirement, The Approver has to validate the employee number manually.Approver will look in some system. There is a check box in Human Task Form " Validated Employee Number". The approver has to check mark this check box befor
-
Resize the number of rejected record in sqlldr
Hi, I am using sqlldr to load my data. However, it is known that the data has lots of error. So when I load my data, after 50 rejected records, the sqlldr stops. It wouldn' load anymore. Question: is there a way to specify the number of rejected reco