Oracle Function with out parameters
Hi, I'm trying to access a stored function on an oracle server with 2 out parameters, 2 in parameters and an out ref cursor.
PL/SQL looks like this
nStatusCode OUT INTEGER,
sStatusMsg OUT VARCHAR2,
sUsrNr IN VARCHAR2,
sPassword IN VARCHAR2,
crsReturn OUT pck_cursor.retRecordSet
I drag the function onto dataset designer and it successfully maps the results to the datatable, it maps datatypes for first out parameters to decimal and string.
the method genearated for fill by looks like (out decimal?,out string,string, string, out object)
problem is, everytime i try to call this function it gives me casting exceptions for the first 2 out parameters, for the decimal it's not specified in more detail. for the other one it says there was an exception casting from OracleString to string. If I change the PL/SQL function to leave the first 2 out parameters away it works fine. Do I manually need to change the TableAdapter definitions??
Hi,
I think I found the problem but not a good solution. It seems to be a problem with auto code generation for TableAdapters in the Dataset wizard. In the Parameter Definition for the Command I set DbType.Decimal and DbType.Sting for the SqlDbtype Property of the out params. The GetData and Fill Method is generated with Fill(out decimal? out1, out string out2). When I look in the generated code ith first sets the SqlDbtype as written but after this also the OracleDbtype to OracleDbType.Decimal and OracleDbType.Varchar2. The casting these types before returning the throws the exception. Any idea how to change this behavior?
Similar Messages
-
Calling a procedure from Oracle Forms with OUT parameter
HI,
Can anyone tell me in detail how to call a procedure with OUT parameters from Oracle Forms 6i ?
Thanks in advance.Hello,
Just provide the out parameter in the call:
Declare
amount number; -- OUT number argument populated by the procedure
Begin
-- call the X procedure --
x( amount ) ;
End;Francois -
I can't execute oracle functions with c#. i'm using oracle 9i version.
i have a problem trying to execute an oracle function with c#.net. The Oracle version i'm using is Oracle 9i.
This is the function definition: (it's defined and working right because i have tryed it with SQLWorksheet)
CREATE OR REPLACE Function NRegistros return integer is
Numero integer(4);
begin
select count(*) into Numero from singles;
return Numero;
END NRegistros;
But with c#.Net i can't acces it because i get an error: "this is not a procedure or is not defined". And i think the code is right. In fact in the same code you can see that i'm using an stored procedure and i have not problems. But with the function i have problems. Is it possible that "OracleClient" can't work with Oracle9i functions??. This is the code:
OracleParameter Parametro = new OracleParameter("Name", OracleType.VarChar,10);
OracleParameter ParametroFuncion = new OracleParameter("Retorno", OracleType.Int32, 4);
Parametro.Direction = ParameterDirection.Output;
ParametroFuncion.Direction = ParameterDirection.ReturnValue;
OracleConnection Conexion = new OracleConnection("Data Source=DISCOS;User Id=SYSTEM;Password=a0000;");
Conexion.Open();
OracleCommand Todos = new OracleCommand();
OracleCommand Procedimiento = new OracleCommand();
OracleCommand Funcion = new OracleCommand();
Todos.Connection = Conexion;
Todos.CommandType = CommandType.Text;
Todos.CommandText="select * from singles";
Procedimiento.Connection = Conexion;
Procedimiento.CommandType = CommandType.StoredProcedure;
Procedimiento.CommandText = "Procedimiento";
Procedimiento.Parameters.Add(Parametro);
Funcion.Connection = Conexion;
Funcion.CommandType = CommandType.StoredProcedure;
Funcion.CommandText = "NRegistros";
OracleDataReader Lector = Todos.ExecuteReader();
BindingSource Discos = new BindingSource();
Discos.DataSource = Lector;
dgvSingles.DataSource = Discos;
Procedimiento.ExecuteNonQuery();
Funcion.ExecuteNonQuery();
lblRegistroProcedimiento.Text = Procedimiento.Parameters["Name"].Value.ToString();
lblNregistros.Text=Funcion.Parameters["Retorno"].Value.ToString();
Conexion.Close();
Edited by: user11921281 on 22-nov-2009 20:32thank you very much. It was a stupid error, sorry. There was one line left :
OracleParameter Parametro = new OracleParameter("Name", OracleType.VarChar,10);
OracleParameter ParametroFuncion = new OracleParameter("Retorno", OracleType.Int32, 4);
Parametro.Direction = ParameterDirection.Output;
ParametroFuncion.Direction = ParameterDirection.ReturnValue;
OracleConnection Conexion = new OracleConnection("Data Source=DISCOS;User Id=SYSTEM;Password=a0000;");
Conexion.Open();
OracleCommand Todos = new OracleCommand();
OracleCommand Procedimiento = new OracleCommand();
OracleCommand Funcion = new OracleCommand();
Todos.Connection = Conexion;
Todos.CommandType = CommandType.Text;
Todos.CommandText="select * from singles";
Procedimiento.Connection = Conexion;
Procedimiento.CommandType = CommandType.StoredProcedure;
Procedimiento.CommandText = "Procedimiento";
Procedimiento.Parameters.Add(Parametro);
Funcion.Connection = Conexion;
Funcion.CommandType = CommandType.StoredProcedure;
Funcion.CommandText = "NRegistros";
Funcion.Parameters.Add(ParametroFuncion); //<--------------------- That one !!! (yes it was a stupid error jeje)
OracleDataReader Lector = Todos.ExecuteReader();
BindingSource Discos = new BindingSource();
Discos.DataSource = Lector;
dgvSingles.DataSource = Discos;
Procedimiento.ExecuteNonQuery();
Funcion.ExecuteNonQuery();
lblRegistroProcedimiento.Text = Procedimiento.Parameters["Name"].Value.ToString();
lblNregistros.Text=Funcion.Parameters["Retorno"].Value.ToString();
Conexion.Close(); -
Question about function with in parameters
Hello,
I have a question about functions with in-parameters. In the HR schema, I need to get the minimum salary of the job_id that is mentioned as an in-parameter.
this is what I am thinking but I dont know if it's correct or not or what should I do next!
create or replace function get_minimum_salary (i_job_id in varchar2)
return number
as
begin
SELECT min_salary INTO min_sal
FROM jobs
where job_id = get_minimum_salary(xy);
RETURN i_job_id;
end get_minimum_salary;
thanks in advance
EDIT
Thanks for your help all.
Is it possible to add that if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:
create or replace procedure insert_error (i_error_code in number,
i_error_message in varchar2)
as
begin
insert into error_table (error_user, error_date, error_code, error_message)
values (user,sysdate,i_error_code,i_error_message);
end insert_error;
This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
Any ideas of how to do that?
Thanks again
Edited by: Latvian83 on Jun 1, 2011 5:14 AMHI
I have made little bit changes in ur code. try this
create or replace function get_minimum_salary (i_job_id in varchar2)
return number
as
v_Min_sal jobs.salary%type=0;---- Variable declaration
begin
SELECT min_salary INTO v_ min_sal
FROM jobs
where job_id = i_job_id;
RETURN v_Min_sal;
end get_minimum_salary;
Regards
Srikkanth.M -
Please help to call oracle procedure with out paramter from shell script
Hi
I want to call a process with out parameter from shell script. I am calling process in shell script in below way
function Process_loads {
( echo 'set serveroutput on size 1000000 arraysize 1'
echo "set pagesize 0 term on verify off feedback off echo off"
echo "BEGIN"
echo " dbms_output.put_line('Before Calling The package'); "
echo " x ( '$1', '$2', '$2', '$4', '$5', '$error_code'); "
echo " dbms_output.put_line('After Calling The package'); "
echo "EXCEPTION "
echo " WHEN OTHERS THEN "
echo " dbms_output.put_line('BIN_LOAD_ERROR' || SQLERRM); "
echo " ROLLBACK;"
echo "END;"
echo "/" ) | sqlplus -s $USER/$PASSWORD@$SID
Here $error_code is out paramter. All varaibles passed in process are declared with export command.
When executing .sh it gives below error
"sh ERROR at line 3: ORA-06550: line 3, column 99: PLS-00363: expression '' cannot be used as an assignment target ORA-06550: line 3, column 3: PL/SQL: Statement ignored".
Please help to get rid from this error or please suggest how to call a oracle procedure with out paramter from unix shell script.
Thanks in advanceYou can try this:
From sql*plus
SQL> ed
1 create or replace procedure my_proc(p_id in int, p_result out int)
2 as
3 begin
4 select 10 * p_id
5 into p_result
6 from dual;
7* end my_proc;
SQL> /
Procedure created.
SQL> set serveroutput on
SQL> declare
2 v_r int;
3 begin
4 my_proc(10,v_r);
5 dbms_output.put_line(v_r);
6 end;
7 /
100
PL/SQL procedure successfully completed.
from bash:
testproc.sh:
#!/bin/bash
(echo 'set serveroutput on';
echo 'declare';
echo 'v_r int;';
echo 'begin';
echo 'my_proc(10,v_r);';
echo 'dbms_output.put_line(v_r);'
echo 'end;';
echo '/';) | sqlplus -s u1/u1
Console:
oracle@mob-ubuntu:~$ chmod u+x testproc.sh
oracle@mob-ubuntu:~$ ./testproc.sh
100
PL/SQL procedure successfully completed.With kind regards
Krystian Zieja -
Using a StoredProcedure with OUT parameters in CrystalReports
Hi All,
I am creating a report using CrystalReport Designer 2008.I have a StoredProcedure which takes 2 input parameters,2 output parameters and a cursor.I am not able to add this SP directly using the DatabaseExpert. if I use
'call SP1(input1,input2,input3,input4,@output1,@output2)' from AddCommand option then it gets added as a Command but the tree under Command does not expand and it does not allow me to use the output parameters in my reports.
Hence,can anyone please help me here such that how should I use this SP with out parameters in my CrystalReports.Also note that I am able to use StoredProcedure with only input parameters,with input parameters and cursor in my CrystalReports.Should I do something extra to add this StoredProcedure in my CrystalReports?
Any help for this issue would be highly appreciated.
Regards.
AjitAjit,
If you are using a Command, you execute a SP in CR with the same syntax that you would in the databases native environment.The only difference is that you'll need to add CR parameters so that the inputs can be added to the SP's input parameters.
So, using your example... 'call SP1({?input1}, {?input2}, {?input3} , {?input4}, output1, output2)'
I'm not familiar with this particular syntax but hopefully you get the idea.
If you want to hard code the input parameters (and not have them prompt in CR), just hard code them in the command.
HTH,
Jason
Edited by: Jason Long on Aug 25, 2010 2:15 PM -
Function with incomplete parameters
I create a function with many parameters
and I call this function through my application
but when I call function I must declare all parameter inside this function like
ddd("a","b",0,0,0,0,0,0,0)
is there a method let function set a default value for parameter if code didn't declare itYou can send just few first parameters and the rest will be passed as false. If you need to pass, say, first and 7th parameter, then you put 6 commas between values, as there is no named parameters in VFP and all parameters are passed by position.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Debug an oracle function with toad 7.4, oracle 9i
Hello,
i wanna debug an oracle function with toad 7.4
so i wanna give param to this function and fix breakpoint and verfy some variables values ... etc
could you show me how debug it?
Thanks
Regards
ElyesDo you have the Toad Debugger? Thats the extra cost option which you get for free in OracleSqlDeveloper.
If you have the ToadDebugger, Read the Manual
If not , download OracleSqlDeveloper and use it. It's free, and written by Oracle. -
Can a function take OUT parameters...?
Hi all.
Can a function take OUT parameters...?
Thanks in advance,
PalYou can do it in PL/SQL but not in SQL. The following example demonstarte that -
satyaki>
satyaki>create or replace package S_glob
2 as
3 b varchar2(20);
4 end;
5 /
Package created.
satyaki>
satyaki>
satyaki>create or replace function S_test_mul_out(a in number,c out varchar2)
2 return number
3 is
4 cursor c1(eno in number)
5 is
6 select ename,job,sal
7 from emp
8 where empno = eno;
9
10 rec c1%rowtype;
11 d number(10);
12 begin
13 open c1(a);
14 loop
15 fetch c1 into rec;
16 exit when c1%notfound;
17 glob.b:= rec.ename;
18 c:= rec.job;
19 d:= rec.sal;
20 end loop;
21 close c1;
22 return d;
23 end;
24 /
Function created.
satyaki>
satyaki>
satyaki>set serveroutput on
satyaki>
satyaki>
satyaki>declare
2 yy varchar2(30);
3 zz number(10);
4 begin
5 ZZ:= s_test_mul_out(7566,yy);
6
7 dbms_output.put_line('Ename: '||glob.b);
8 dbms_output.put_line('Job: '||yy);
9 dbms_output.put_line('Sal: '||zz);
10 end;
11 /
Ename: JONES
Job: MANAGER
Sal: 1000
PL/SQL procedure successfully completed.
satyaki>Regards.
Satyaki De.
Message was edited by:
Satyaki_De -
Executing sql server procedure from oracle via db link with out parameters
HI
we have successfully created the link between oracle and sql server via DB LINK also able to access table from the
sqlserver via dblink
Can any one tell me how to execute procedure with 1 input and 4 out parameters from pl\sql
is it possible using
dbms_hs_passthroughYou should be able to call it like you would any other procedure:
dbo.procedure_name@dblink(parameter_list); -
How to call a Stored Function with OUT parameter of %rowType from Java
Hi everyone,
I'm getting crazy trying to make this work.
I have a function (not developed by me) in Oracle 10g declared in this way:
type tab_RLSSP is table of TB_RLSSP_STOSTPRPAR_CL%ROWTYPE index by binary_integer;
FUNCTION DBF_PERL_LISTA_PRATICHE (
p_id_va IN NUMBER,
p_seq_partita IN NUMBER,
p_trattamento IN CHAR,
lrec_RLSSP OUT tab_RLSSP ) RETURN NUMBER;
And here is the code snipplet of my java method:
sql="{? = call "+SCHEMA+PACKAGE+"."+FUNCTION_LIST+"(?,?,?,?)}";
cs=connection.prepareCall(sql);
cs.registerOutParameter(1, OracleTypes.NUMBER);
cs.setLong(2,idVATitolare);
cs.setLong(3,seqPartita);
cs.setString(4,trattamento);// Caso Decesso
cs.registerOutParameter(5, OracleTypes.OTHER);
cs.executeQuery();
result = (ResultSet) cs.getObject(5);
if (result.next())
listaPratiche.add(readPraticaPartita(result));
The result (exception thrown at executeQuery with statement generated as
SQL : {? = call PEDBA.DBK_PERL_RATEI_SUPPLETIVI.DBF_PERL_LISTA_PRATICHE(?,?,?,?)}:
java.sql.SQLException: ORA-06550: line 1, column 13:
PLS-00306: wrong number or types of arguments in call to 'DBF_PERL_LISTA_PRATICHE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Changing to :
sql="{call ? := "+SCHEMA+PACKAGE+"."+FUNCTION_LISTA+"(?,?,?,?)}";
leading to
SQL : {call ? := call PEDBA.DBK_PERL_RATEI_SUPPLETIVI.DBF_PERL_LISTA_PRATICHE(?,?,?,?)}
don't change anything.
What's wrong? Any suggestion?
Edited by: 957158 on 5-set-2012 9.06>
Taking for granted that it works, I wonder what's different, probably the output is defined as Cursor...
>
You mean because of this line?
cs.registerOutParameter(5,OracleTypes.CURSOR);You can either use a cursor or use a function that returns a SQL type instead of the PL/SQL type.
Here is sample code using a cursor
CREATE OR REPLACE TYPE SCOTT.local_type IS OBJECT (
empno NUMBER(4),
ename VARCHAR2(10));
CREATE OR REPLACE TYPE SCOTT.local_tab_type IS TABLE OF local_type;
CREATE OR REPLACE PACKAGE SCOTT.test_refcursor_pkg
AS
TYPE my_ref_cursor IS REF CURSOR;
-- add more cursors as OUT parameters
PROCEDURE test_proc(p_ref_cur_out OUT test_refcursor_pkg.my_ref_cursor);
END test_refcursor_pkg;
CREATE OR REPLACE PACKAGE BODY SCOTT.test_refcursor_pkg
AS
PROCEDURE test_proc(p_ref_cur_out OUT test_refcursor_pkg.my_ref_cursor)
AS
l_recs local_tab_type;
BEGIN
-- Get the records to modify individually.
SELECT local_type(empno, ename) BULK COLLECT INTO l_recs
FROM EMP;
-- Perform some complex calculation for each row.
FOR i IN l_recs.FIRST .. l_recs.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(l_recs(i).ename);
END LOOP;
-- Put the modified records back into the ref cursor for output.
OPEN p_ref_cur_out FOR
SELECT * from TABLE(l_recs);
-- open more ref cursors here before returning
END test_proc;
END;
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
l_cursor test_refcursor_pkg.my_ref_cursor;
l_ename emp.ename%TYPE;
l_empno emp.empno%TYPE;
BEGIN
test_refcursor_pkg.test_proc (l_cursor);
LOOP
FETCH l_cursor
INTO l_empno, l_ename;
EXIT WHEN l_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(l_ename || ' | ' || l_empno);
END LOOP;
CLOSE l_cursor;
END;
/ -
Procedure with OUT Parameters - Creating A Report
I have the following procedure that is used in our internal (non-APEX) apps:
PROCEDURE SelIssueActivityPublic (
p_results OUT SYS_REFCURSOR,
p_IssueID IN ems.issue.issue_id%TYPE,
p_TransactionID OUT VARCHAR2
) The body of the procedure does a bunch of processing, and inserts data into a staging table. The cursor OUT parameter then returns a SELECT statement from the staging table. Since it's possible for this procedure to be hit multiple times (multiple users), the transaction ID is used to match the data in the staging table to the correct request. The procedure then deletes the data from the staging table. (I'll post it if necessary, but it's quite long, and since it's used in other applications successfully, I don't believe it's relevant to my issue.)
I have been asked to create an APEX report of the data generated by the procedure. I've never used a procedure with an OUT parameter to set up a report. I was hoping to assign the transaction ID to a hidden variable on page load, and then using it to poplulate the report. I'm not interested in the cursor OUT parameter, I've written my own SELECT statement to grab data from the staging table.
I tried to create a page computation that did this - item :H_P19_TRANSID, Before Header, computation = EMS.EMS_READER.SelIssueActivityPublic(:H_P19_CURSOR, 454551, :H_P19_TRANSID) [454551 is a test issue id], but I get the following error: ORA-06550: line 1, column 43: PLS-00222: no function with name 'SELISSUEACTIVITYPUBLIC' exists in this scope ORA-06550: line 1, column 7: PL/SQL: Statement ignored flowComp=H_P19_TRANSID
Error ERR-1030 Error executing computation expression. It seems to be thinking that SelIssueActivityPublic is a function, and I'm not sure why.
Basically I need to know how to use this existing procedure to set up my report. Once I can get the transaction ID into a page item, I'll be set.I never got a chance to finish this report, as I was shuffled to something else with a higher priority. Now that I'm coming back to it, I still have a few issues.
I created a new function that does all the processing (inserting into the staging table etc.), and returns the transaction id. I then tried to set up a page computation on a hidden item to run this function and store the transaction id.
In the computation, if I put
reader.SelIssueActivityPubnocursor(:H_P19_ISSUEID); as the computation, I get ORA-06503: PL/SQL: Function returned without value flowComp=H_P19_TRANSACTIONID as an error. If I put return return reader.SelIssueActivityPubnocursor(:H_P19_ISSUEID); as the computation, I get ORA-06550: line 1, column 50: PLS-00103: Encountered the symbol "EMS" when expecting one of the following: . ( * @ % & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like like2 like4 likec between || multiset member submultiset The symbol "." was substituted for "EMS" to continue. flowComp=H_P19_TRANSACTIONID as the error. Can someone tell me what's going wrong? -
Oracle functions with PowerPivot
Hi All,
I have a requirement of building reports using Oracle functions in PowerPivot.
I have tried using Table Import Wizard and Command Type=StoredProcedure in th ePowerPivot.
Any help will be appreciated.
Thanks and Regards,
SSHello,
I don't think we can use Oracle functions/stored procedures in PowerPivot, please see the similar thread below:
http://social.technet.microsoft.com/Forums/en-US/22e67f7f-0753-4f21-bae2-1812d2daf03e/powerpivot-oracle-stored-procedure-err-the-sql-statement-is-not-valid-there-are-no-columns?forum=sqlkjpowerpivotforexcel
I would suggest you elaborate your requirement with more detail.
Regards,
Elvis Long
TechNet Community Support -
Executing procedures with OUT parameters using Named notation
I have a procedure with two out parameters (p_errortext and p_returncode) and i want to execute this proc in SQL*plus using named notation(using association operator ' => '). For position based execution i usually declare variables to hold the OUT parameter's value. But how can i do this while executing using named notation (using => )
begin
packagename.generate_ref_record(p_userid => 'THELMA',
p_ref_code => '9A',
p_item_id => '9990000011163',
p_shipno => '0PH',
p_errortext => ??
p_returncode => ??);
end;SQL>variable x varchar2(30);
SQL>variable y varchar2(30);
SQL>exec packagename.generate_ref_record(p_userid => 'THELMA',
p_ref_code => '9A',
p_item_id => '9990000011163',
p_shipno => '0PH',
p_errortext => :x
p_returncode => :y); -
Hi All,
I have pondered over this for long but coudnt find a way myself..How do I declare and use an OUT param in an Oracle function,considering it can return only one value at a time. I would appreciate if you can give an example and explain.
Thanks.SQL> create or replace function f1(p1 in number,p2 out varchar2)
2 return number is
3 begin
4 p2 := 'i am returning '||p1*2;
5 return p1*2;
6 end;
7 /
SQL> declare
2 n number;
3 v varchar2(20);
4 begin
5 n := f1(5,v);
6 dbms_output.put_line(v);
7 dbms_output.put_line(n);
8 end;
9 /
i am returning 10
10
PL/SQL procedure successfully completed.
Message was edited by:
jeneesh
Better you post the specific problem..
Maybe you are looking for
-
What is the best large monitor (24"or 27") to use with my 2011 Mac Book Pro?
-
HT204053 Why can't I make a purchase on my iPad
Why can't I make a purchase on my iPad
-
D10 freezes with NVS290 and 2 x Matrox T30 PCI graphic card
Hi, I have a problem with D10 that have NVS290 as a standard graphic card and then 2 x Matrox T30 PCI graphic. I have updated to the most recent BIOS and still my system freezes. It has been testes on Dell and HP workstation and it;s working well. Ca
-
Printing with Business Objects in Forte 2.0.f
Hello, Where are trying to get businessObject to work within the Forte environment (2.0.F), but we are stuck. Does anyone uses Business objects as a printing tool together with Forte, and if so, how is this done?? Hans van Drunen Philip Morris Münche
-
Best option for upgrading to CS 6
Hello, I need some help. I currently have CS 5 and 5.5 installed across 7 PCs and 1 MAC within the marketing department in my company. What would be the best option for upgrading all of them to CS 6 Master Collection. (how many PCs can I use a licens