How to execute a procedure if out parameter is table type
Hi,
I need to execute a procedure, output parameter of the procedure is table type.
Oracle version I am using is 9.2.0.8 . I am using SQL*Plus
Procedure declaration
PROCEDURE current_open_cycle (p_ban IN repl_cust2.billing_account.ban%TYPE,
v_bill_seq_rec OUT bill_seq_table) ;
Table type declaration
TYPE bill_seq_table IS
TABLE OF bill_seq_rectype INDEX BY BINARY_INTEGER ;
TYPE bill_seq_rectype IS RECORD (v_cycle_run_year repl_cust2.bill.cycle_run_year%TYPE,
v_cycle_run_month repl_cust2.bill.cycle_run_month%TYPE,
v_cycle_code repl_cust2.bill.cycle_code%TYPE,
v_open_cycle BOOLEAN, -- An open cycle
v_billed_cycle BOOLEAN, --
v_invoice_number VARCHAR2(13),
v_start_date DATE,
v_end_date DATE,
v_root_ban repl_cust2.bill.root_ban%TYPE) ;
I tried executing using this script, but it failed. When I execute this oracle lost connection to data base.
declare
r_bill_seq_rec ss_invoice_utilities.bill_seq_table;
begin
ss_invoice_utilities.current_open_cycle(934018003,r_bill_seq_rec);
end;
Please help me how I should write declare block to execute this procedure and also print output of the procedure.
Regards
Raghu
I don't see anything wrong with the anonymous block, assuming ss_invoice_utilities is the correct package name. Perhaps a simplified test case would show up what's not working there.
As for printing the contents of an associative array, you'll have to write some code to loop through it and construct a string per row to output via dbms_output, assuming the text will fit within dbms_output's size restrictions in 9i. dbms_output is a debugging tool though - is that the requirement?
btw "pls_integer" is less to type than "binary_integer" ;)
Edited by: William Robertson on Apr 16, 2009 8:35 AM
Similar Messages
-
How to write a shell script to execute a procedure with out parameter
Hi,
How to write a shell script to execute a procedure with out parameter.
here is my procedure
PROCEDURE sample(invar1 VARCHAR2,
invar2 VARCHAR2,
invar3 VARCHAR2,
invar4 VARCHAR2,
ecode out number);
Any example really helpfull
Thanks in advanceOr if we're passing values in, maybe something like:
Test procedure:
CREATE OR REPLACE PROCEDURE p (myin IN VARCHAR2, myout OUT VARCHAR2)
AS
BEGIN
myout :=
CASE myin
WHEN 'A' THEN 'APPLE'
WHEN 'B' THEN 'BANANA'
ELSE 'STARFRUIT'
END;
END;Shell script:
#!/bin/bash
my_shell_variable=$1
unset ORACLE_PATH
sqlplus -s un/pw@db <<-EOF
set feedback off pause off
set pagesize 0
set autoprint off
VAR out varchar2(30)
VAR myin varchar2(30)
exec :myin := '${my_shell_variable}'
BEGIN
p(:myin, :out);
END;
print out
exit
EOFTest:
/Users/williamr: xx A
APPLE
/Users/williamr: xx B
BANANA
/Users/williamr: xx
STARFRUITObviously in a real script you would not hardcode the password or let it show in a "ps" listing.
Message was edited by:
William Robertson -
How to exec. stored procedure having out parameter value in shell script ?
Hi Gurus,
I am writing a shell script which is calling a SP having out parameter as varchar2.
So how can i do this in shell scripting ? (I am a new in shell scripting)
a simple example is preferred.
Thanks
SandySo how can i do this in shell scripting ? Assuming you want to assign the out parameter value to a shell variable, here's a small example :
SQL> select ename from emp where empno=7902;
ENAME
FORD
SQL> create or replace procedure show_name (
2 v_empno in number,
3 v_ename out varchar2)
4 is
5 begin
6 select ename into v_ename from emp
7 where empno = v_empno;
8 end;
SQL> /
Procedure created.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
$ cat show_name.sh
ENAME=`sqlplus -s test/test << EOF
set pages 0
set feed off
var V1 varchar2(30);
exec show_name($1, :V1);
print V1
exit
EOF`
echo $ENAME
$ ./show_name.sh 7902
FORD
$ -
How to execute this procedure(having out parameters)
PROCEDURE emp_cursor (
v_deptno IN VARCHAR2,
v_doj OUT DATE,
v_empno OUT NUMBER,
v_sal OUT NUMBER
);Hi,
812809 wrote:
PROCEDURE emp_cursor (
v_deptno IN VARCHAR2,
v_doj OUT DATE,
v_empno OUT NUMBER,
v_sal OUT NUMBER
emp_cursor ( expr_1
, var_2
, var_3
, var_4
);Where var_2, var_3 and var_4 are variables with the appropriate data types. You must pass variables for the OUT parameters.
Expr_1 can can a variable, a literal, or any other kind of expression that evaluates to a VARCHAR2.
I hope this answers your question.
If not, post a little a simple test script (with as much of the coding as you know how to do) so that people can re-create the problem and test their ideas. Post the results you want from that code. Explain how you get those results.
Always say which version of Oracle you're using. -
How to execute the procedure in sap b1
Hai to all,
I done a procedure in sql server .but i don't know how to execute that procedure in sap b1?
can anyone help me immediately.
Regards,
Ramya.SDear Ramya.S,
You could execute the store procedure by using Recordset object in SDK DI code. It is like:
Dim myRecordSet As SAPbobsCOM.Recordset
myRecordSet =
SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecord
set)
myRecordSet.Command.Name = "TestStoredProcedure"
myRecordSet.Command.Parameters.Item("@ItemLike").Value = "IT%"
myRecordSet.Command.Parameters.Item(2).Value = "C0001"
myRecordSet.Command.Execute() -
How to execute a procedure with Object as OUT parameter
Hi,
I have a procedure and it consists 2 parameter, one is an input parameter and that is some ID (NUMBER datatype) and 2nd parameter is an out parameter and it an Object type. I want to execute that procedure but not able to do the same. Can anyone please suggest me how do I execute a procedure which has got Object as an out parameter.
Thanks a lot in advance for your support.Example:
SQL> create or replace type t_obj as object (ename varchar2(10), deptno number);
2 /
Type created.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure myproc (p_empno in number, obj out t_obj) is
2 begin
3 select t_obj(ename, deptno)
4 into obj
5 from emp
6 where empno = p_empno;
7* end;
SQL> /
Procedure created.
SQL> set serverout on
SQL> declare
2 v_obj t_obj;
3 begin
4 myproc(7788, v_obj);
5 dbms_output.put_line(v_obj.ename||','||v_obj.deptno);
6 end;
7 /
SCOTT,20
PL/SQL procedure successfully completed. -
How to execute dynamically created procedure with out parameter
hi guys ,
friend i have to execute a procedure whose name is going to change dynamically and this procedure is have 2 out parameter . I need to capture value of these 2 output parameter, here i m giving my code also ..
declare
v_emp_id int :=100013 ;
p_reg_off varchar(5) := 'R' ;
p_user_id int := 6 ;
v_status varchar(200);
v_message varchar (200);
v_Formula varchar(100);
v_number int := 1 ;
begin
v_Formula := 'Call testsp_'||v_number||'('||v_emp_id||','''||p_reg_off||''','|| p_user_id || ',v_status,v_message)' ;
DBMS_OUTPUT.PUT_LINE( v_Formula);
execute immediate v_Formula;
end ;
and my procedure structure is like this
CREATE OR REPLACE PROCEDURE testsp_1
p_emp_id INT,
p_reg_off CHAR,
p_user_id INT,
p_status OUT NOCOPY INT,
p_message OUT NOCOPY VARCHAR2
AS
begin
end ;
please help me .....The Complete Syntax for Execute Immediate is ::
EXECUTE IMMEDIATE dynamic_sql_string
[INTO {define_variable,... | INTO record_name}]
[USING
IN bind_argument,...]
[RETURN[ING] INTO
bind_argument,...];
i think now it won't be a problem! ;) -
How can I execute a Procedure with OUT variable is %ROWTYPE on SQL Prompt
Hi,
I have a procedure with OUT variable is %ROWTYPE
How can I execute the following procedure on SQL prompt.
(without creating anonymous block)
CREATE OR REPLACE PROCEDURE zz_sp_EMP(VEMPNO IN EMP.EMPNO%TYPE,
V_REC IN OUT EMP%ROWTYPE)
AS
BEGIN
SELECT * INTO V_REC FROM EMP WHERE EMPNO = VEMPNO;
END;
Thanks & Regards,
Nareshas previous posters said: it's not possible to do this without declaring a variable in the anonymous block.
With anonymous block it would look like this (had to change it a bit, since i'm using hr-schema on oracle XE):
declare
l_rec EMPLOYEES%ROWTYPE;
begin
zz_sp_EMP(VEMPNO => 100, V_REC => l_rec);
DBMS_OUTPUT.PUT_LINE ( 'first_name = ' || l_rec.first_name );
DBMS_OUTPUT.PUT_LINE ( 'last_name = ' || l_rec.last_name );
end;
first_name = Steven
last_name = King -
Execute immediate for stored procedure with out parameter
Hi,
I have problem with dynamically executing the statement hope anyone can help me.
I have a table which stores the procedure names. and procedure parameter values are stored on another column with parameter values coming from java side.
I have to create a procedure that dynamically executes the procedure on table1 with the values from table 2.
Now I'm getting real trouble to execute immediate this proc with parameters. I tried the DBMS_SQL package as well.
Problem is you need to mention the OUT mode specifically for the out parameter. Can anybody plz help me with this issue??
TABLE1_
PROCESS_ID PROC_NAME
1 proc1(p1 IN number, p2 IN varchar2, p3 OUT varchar2)
2 proc2(p1 IN number, p2 out varchar2, p3 OUT varchar2)
TABLE2_
PROCESS_ID PROC_PARMS
1 100, 'test', :return
2 200, :return1, :return2
Thank You826957 wrote:
Hi,
I have problem with dynamically executing the statement hope anyone can help me.
I have a table which stores the procedure names. and procedure parameter values are stored on another column with parameter values coming from java side.
I have to create a procedure that dynamically executes the procedure on table1 with the values from table 2.
Now I'm getting real trouble to execute immediate this proc with parameters. I tried the DBMS_SQL package as well.
Problem is you need to mention the OUT mode specifically for the out parameter. Can anybody plz help me with this issue??
TABLE1_
PROCESS_ID PROC_NAME
1 proc1(p1 IN number, p2 IN varchar2, p3 OUT varchar2)
2 proc2(p1 IN number, p2 out varchar2, p3 OUT varchar2)
TABLE2_
PROCESS_ID PROC_PARMS
1 100, 'test', :return
2 200, :return1, :return2
Thank YouSounds like an appalling design and a nightmare waiting to happen.
Why not have your Java just call the correct procedures directly?
Such design smells badly of an entity attribute value modelling style of coding. Notoriously slow, notoriously buggy, notoriously hard to maintain, notoriously hard to read. It really shouldn't be done like that. -
Please help....execute procedure with out parameter -cursor
HI all plese help me,
i create a stored procedure like this.hw cani execute the IN out parameter which is a cursor ir..RCT1 is cursor..
please help...
CREATE OR REPLACE PROCEDURE ST_GetTravelTypeID
TravelType IN VARCHAR2 DEFAULT NULL,
RCT1 IN OUT GLOBALPKG.RCT1
AS
BEGIN
OPEN RCT1 FOR
SELECT
TravelTypeCode,
TravelTypeDesc
FROM ST_MS_TravelTypes
WHERE TravelType = ST_GetTravelTypeID.TravelType;
END;
Message was edited by:
neethuYour reference is invalid:
WHERE TravelType = ST_GetTravelTypeID.TravelType;
This should not (cannot) refer to the name of the procedure - but simply to the variable in it. I.e.
WHERE TravelType = TravelType;
However, as you can see, the variable name is now the same as the column name.
One method around this is to use explicit scope reference. E.g.
SELECT
t.TravelTypeCode,
t.TravelTypeDesc
FROM ST_MS_TravelTypes t
WHERE t.TravelType = TravelType;I suggest that you consider this a standard for your PL/SQL programming. Always alias SQL tables in PL/SQL code and use explicit column references.
Another standard we use is to use underscore characters for columns - camel case is fine for variables in a programming language. This is not really acceptable for column names, as by default Oracle uses uppercase. Thus "TravelType" is valid as variable name, but invalid as a column name - it should be defined/written as "travel_type" or "TRAVEL_TYPE" instead. -
Execute procedure with out parameter in sql*plus
HI All,
I am executing an stored proc with OUT parameter from sql*plus.
Getting this error message:
SQL> execute sp1_cr_ln_num('01',0,3);
BEGIN sp1_cr_ln_num('01',0,3); END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to
'sp1_cr_ln_num'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Whereas it works fine using Toad. 4th parameter is for output.
Thanks.then you can see the value either using print :var or execute dbms_output.put_line(:var)
-
How to execute a procedure with collection passed as parameter?
i have created the collection:
CREATE TYPE typ_Project AS OBJECT( project_no NUMBER(2), title VARCHAR2(35), cost NUMBER(7,2))
CREATE TYPE typ_ProjectList AS VARRAY (50) OF typ_Project
and a procedure:
CREATE OR REPLACE PROCEDURE add_project (
p_deptno IN NUMBER,
p_new_project IN typ_Project,
p_position IN NUMBER )
IS
v_my_projects typ_ProjectList;
BEGIN
SELECT projects INTO v_my_projects FROM department
WHERE dept_id = p_deptno FOR UPDATE OF projects;
v_my_projects.EXTEND;
FOR i IN REVERSE p_position..v_my_projects.LAST - 1 LOOP
v_my_projects(i + 1) := v_my_projects(i);
END LOOP;
v_my_projects(p_position) := p_new_project; -- add new
UPDATE department SET projects = v_my_projects
WHERE dept_id = p_deptno;
END add_project;
Now please explain how to call this procedure with collection passed as parameter . . .For example:
BEGIN
add_project(
10, -- department number
typ_Project(
99, -- project number
'New Project', -- project title
99999.99 -- project cost
), -- new project
5 -- project position
END;
/SY. -
About JDBC CALL STORE PROCEDURE with out parameter is greater than 4000
Hi Guys,
I have a problem call store procedure with a large string.
as i know varchar2 can contain 32767 characters in pl/sql .
But when i used varchar2 as a out parameter in a store procedure, if the out parameter is greater than 4000 characters , it always give me error message as 'the buffer is too small'.
why it happened?
I read some article that says i need configure a property in data-source.xml , and jdbc 10g driver already solved this problem, but i used jdev 10.1.3.2 ,the driver should be fine.
How can i solve this problem?
Thanks in advance,
AppCatObject is Foundation, Execute Script
This is for a query, you can change to a stored procedure call. Pull the value back in the Java code then put into the process variable.
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:IDP_DS");
conn = ds.getConnection();
stmt = conn.prepareStatement("select FUBAR from TB_PT_FUBAR where PROCESS_INSTANCE_ID=?");
stmt.setLong(1, patExecContext.getProcessDataLongValue("/process_data/@inputID"));
rs = stmt.executeQuery();
rs.next();
patExecContext.setProcessDataStringValue("/process_data/outData", rs.getString(1));
} finally {
try {
rs.close();
} catch (Exception rse) {}
try {
stmt.close();
} catch (Exception sse) {}
try {
conn.close();
} catch (Exception cse) {} -
Can you tell me how to execute the procedure?
create or replace get_dob
(ss_number varchar2,dob out date)
as
begin
select birth_dae
into dob
from person
where soc_sec_num=ss_num;
exception when no_data_found
error_notify(ss_num);
end;
the question is that when i want to execute this procedure,how can I use the command?
I try to use the "execute get_dob('wang');"in the sql/plus,but the system give me wrong information.Errors:
1. You left out the word PROCEDURE after CREATE OR REPLACE.
2. You used ss_number in one place and ss_num in two others. These must be the same name.
3. You left out the word THEN after WHEN NO_DATA_FOUND.
Possible errors:
1. Is birth_dae spelled correctly? Or, should it be birth_date?
2. Is error_notify a user-defined procedure?
Additional suggestions:
1. It is better to use table_name.column_name%TYPE instead of specifying NUMBER, VARCHAR2, DATE, etc. for your parameters. That way if the column data types are changed in the future, you don't have to change your code.
2. You will need to SET SERVEROUTPUT ON and use DBMS_OUTPUT.PUT_LINE to display the contents of the variable that holds the value of the out parameter.
3. Please see suggested code for creation of procedure and execution of procedure below. I have included one row of test data so that some output will be displayed. I commented out the exception section, in order to test it, since I don't have your error_notify procedure.
SQL> -- test data:
SQL> CREATE TABLE person
2 (birth_dae DATE,
3 soc_sec_num NUMBER)
4 /
Table created.
SQL> INSERT INTO person
2 VALUES (SYSDATE, '123456789')
3 /
1 row created.
SQL> SELECT * FROM person
2 /
BIRTH_DAE SOC_SEC_NUM
06-DEC-02 123456789
SQL>
SQL>
SQL> -- create procedure:
SQL> CREATE OR REPLACE PROCEDURE get_dob
2 (ss_number IN person.soc_sec_num%TYPE,
3 dob OUT person.birth_dae%TYPE)
4 AS
5 BEGIN
6 SELECT birth_dae
7 INTO dob
8 FROM person
9 WHERE soc_sec_num = ss_number;
10 -- EXCEPTION
11 -- WHEN NO_DATA_FOUND THEN
12 -- error_notify (ss_number);
13 END get_dob;
14 /
Procedure created.
SQL> SHOW ERRORS
No errors.
SQL>
SQL>
SQL> -- execute procedure:
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 v_dob DATE;
3 BEGIN
4 get_dob ('123456789', v_dob);
5 DBMS_OUTPUT.PUT_LINE (v_dob);
6 END;
7 /
06-DEC-02
PL/SQL procedure successfully completed. -
How to Execute the procedure?
Hi,
How to execute a below procedure with refcursor output parameter,
in that procedure refcursor declare in package
create or replace PROCEDURE prc_sam(
P_LIST OUT pkg_sam.REF_CURSOR_TYPE) IS
BEGIN
OPEN P_LIST FOR
SELECT 1+1 FROM dual;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,SQLERRM);
END prc_sam;
Regards,
FameSQL> create or replace PROCEDURE prc_sam(
2 P_LIST OUT SYS_REFCURSOR) IS
3 BEGIN
4
5 OPEN P_LIST FOR
6 SELECT 1+1 FROM dual;
7 EXCEPTION
8 WHEN OTHERS THEN
9 RAISE_APPLICATION_ERROR(-20001,SQLERRM);
10 END prc_sam;
11 /
Procedure created.
SQL> VARIABLE P_CURSOR REFCURSOR;
SQL> EXEC prc_sam(:P_CURSOR);
PL/SQL procedure successfully completed.
SQL> PRINT P_CURSOR;
1+1
2
Intead of SYS_REFCURSOR, you can use ur pkg_sam.REF_CURSOR_TYPE inside a package
AND
execute a procedure like EXEC pkg_sam.prc_sam(:P_CURSOR);
like this, then you will get the result............................
Thanks,
Ann
Maybe you are looking for
-
Is there a way to create DVDs from movies made in iMovie on the iPad?
Is there a way to create DVDs from movies made in iMovie on the iPad? I have a PC. Thanks
-
TS3694 how will i turn on my iphone3g?
i updated my iphone 3g (4.2.1)now it needs to be restored in the itunes but it said iphone could not be restored error 1015 now i cant open my iphone3g...i cant used it anymore.
-
Hi, I have a project where it is imperative that i know the calling class and the called class name. I have a solution working where i place the caled class on a stack and record it as a possible calling class. However there must be a simpler means o
-
Procurement of Assets and MRO items
HI all, Can anyone share with me if return delivery is applicable to procurement of MRO items(acct assigned K) or Assets(acct assigned A)? Not sure if return delivery can be done for consumable materials..Hope to have a clearer concept on return deli
-
Is iphone 5s 16gb available in factory unlocked version in USA?
is iphone 5s 16gb available in factory unlocked version in USA