Printing OUT variables from a Stored Procedure
Hi all,
I'm running an SQL command that calls a Stored Procedure and passes in some value. I've pasted in the important parts of it below. What I am trying to do is access the OUT variables that have been assigned to the DECLARED variables. I come from a SQL Server background and there we can do "SELECT @variable" which will print it to screen. I'm trying to do something similar here.
I need to access the contents of the three variables declared at the top of the script.
Thanks in advance.
DECLARE
l_error_value NUMBER;
l_error_product VARCHAR2 (10);
l_CE_DOC_ID number;
BEGIN
PEM.create_enquiry
( ce_cat => 'COMP'
, ce_class => 'FRML'
, error_value => l_ERROR_VALUE
,error_product => l_ERROR_PRODUCT
, ce_doc_id => l_ce_doc_id
END;
Ah yes I see. Sorry I misunderstood what you were suggesting. I'm currently working on a test script that uses an approach similar to the one you mentioned, but I'm having trouble resolving foreign key relationships with test data.
I've no access to the tables or anything so it's proving to be a time consuming task!!
Is it required that all fields are given a value, even if they have a "DEFAULT" defined for them within the procedure. At the moment I'm using a rather cumbersome approach to this:
i.e.
With cmmAddRequest
.ActiveConnection = strConnect
.CommandType = adCmdText
.CommandText = strSQL
.Parameters(0).Direction = adParamInput
.Parameters(1).Direction = adParamInput
.Parameters(2).Direction = adParamInput
.Parameters(3).Direction = adParamOutput
.Parameters(4).Direction = adParamOutput
.Parameters(5).Direction = adParamOutput
.Parameters(0).Value = "COMP"
.Parameters(1).Value = "FRML"
.Parameters(2).Value = "1"
.Execute
WScript.Echo(.Parameters(5).Value)
End With
Similar Messages
-
How to use OUT variables in my stored procedure
I'm wondering if I can get some help using OUT variables in my stored procedure. Here's my code...
CREATE OR REPLACE PROCEDURE testProj.testProcedure (
v_segment_id IN VARCHAR2,
v_student_id OUT VARCHAR2,
v_current_code OUT NUMBER,
v_new_code OUT NUMBER
) AS
BEGIN
SELECT
s.student_id,
s.quad_code_id,
nc.quad_code_id
INTO
v_student_id,
v_current_quad_code,
v_new_quad_code
FROM testProj.students s
INNER JOIN testProj.new_codes nc ON s.student_id = nc.student_id
WHERE s.segment_id = v_segment_id ;
END testProcedure ;
EXECUTE testProj.testProcedure ('44') ;
When I execute that stored procedure with the above execute statement, I get this error:
Error report:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'testProcedure'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
+06550. 00000 - "line %s, column %s:\n%s"+
*Cause: Usually a PL/SQL compilation error.+
*Action:+Using Refcursor is one way you can do that ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.21
satyaki>
satyaki>
satyaki>create or replace procedure r_arg(
2 choice in number,
3 b in out sys_refcursor
4 )
5 is
6 str varchar2(500);
7 begin
8 str := 'select * from emp';
9 open b for str;
10 exception
11 when others then
12 dbms_output.put_line(sqlerrm);
13 end;
14 /
Procedure created.
Elapsed: 00:00:01.84
satyaki>
satyaki>
satyaki>declare
2 rec_x emp%rowtype;
3 w sys_refcursor;
4 begin
5 dbms_output.enable(1000000);
6 r_arg(1,w);
7 loop
8 fetch w into rec_x;
9 exit when w%notfound;
10 dbms_output.put_line('Employee No: '||rec_x.empno||' - '||
11 'Name: '||rec_x.ename||' - '||
12 'Job: '||rec_x.job||' - '||
13 'Manager: '||rec_x.mgr||' - '||
14 'Joining Date: '||rec_x.hiredate||' - '||
15 'Salary: '||rec_x.sal||' - '||
16 'Commission: '||rec_x.comm||' - '||
17 'Department No: '||rec_x.deptno);
18 end loop;
19 close w;
20 exception
21 when others then
22 dbms_output.put_line(sqlerrm);
23 end;
24 /
Employee No: 9999 - Name: SATYAKI - Job: SLS - Manager: 7698 - Joining Date: 02-NOV-08 - Salary: 55000 - Commission: 3455 - Department No: 10
Employee No: 7777 - Name: SOURAV - Job: SLS - Manager: - Joining Date: 14-SEP-08 - Salary: 45000 - Commission: 3400 - Department No: 10
Employee No: 7521 - Name: WARD - Job: SALESMAN - Manager: 7698 - Joining Date: 22-FEB-81 - Salary: 1250 - Commission: 500 - Department No: 30
Employee No: 7566 - Name: JONES - Job: MANAGER - Manager: 7839 - Joining Date: 02-APR-81 - Salary: 2975 - Commission: - Department No: 20
Employee No: 7654 - Name: MARTIN - Job: SALESMAN - Manager: 7698 - Joining Date: 28-SEP-81 - Salary: 1250 - Commission: 1400 - Department No: 30
Employee No: 7698 - Name: BLAKE - Job: MANAGER - Manager: 7839 - Joining Date: 01-MAY-81 - Salary: 2850 - Commission: - Department No: 30
Employee No: 7782 - Name: CLARK - Job: MANAGER - Manager: 7839 - Joining Date: 09-JUN-81 - Salary: 4450 - Commission: - Department No: 10
Employee No: 7788 - Name: SCOTT - Job: ANALYST - Manager: 7566 - Joining Date: 19-APR-87 - Salary: 3000 - Commission: - Department No: 20
Employee No: 7839 - Name: KING - Job: PRESIDENT - Manager: - Joining Date: 17-NOV-81 - Salary: 7000 - Commission: - Department No: 10
Employee No: 7844 - Name: TURNER - Job: SALESMAN - Manager: 7698 - Joining Date: 08-SEP-81 - Salary: 1500 - Commission: 0 - Department No: 30
Employee No: 7876 - Name: ADAMS - Job: CLERK - Manager: 7788 - Joining Date: 23-MAY-87 - Salary: 1100 - Commission: - Department No: 20
Employee No: 7900 - Name: JAMES - Job: CLERK - Manager: 7698 - Joining Date: 03-DEC-81 - Salary: 950 - Commission: - Department No: 30
Employee No: 7902 - Name: FORD - Job: ANALYST - Manager: 7566 - Joining Date: 03-DEC-81 - Salary: 3000 - Commission: - Department No: 20
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.48
satyaki>
satyaki>Regards.
Satyaki De. -
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 do I retrieve a variable from a stored procedure in Access?
Given a stored procedure like the one below,
PROCEDURE getSomething(
pVar1 in float,
pVar2 in float,
pVar3 in float,
pVar4 in float,
pResults out varchar2
How would I retrieve the value in pResults using VBA on Access? Thanks.Using this, you can set the value to the session bean
<c:set property="docID" target="${SessionBean1}" value="${pg_view_doc.hiddenField3.value}"/>
But before that you have to create a property called docid in the sessionbean1.
So once the property is set, through getDocID() method u can retrieve the value
ex: String value=getSessionBean1().getDocID();
will return the value in the required JSF Page bean -
Get variable values from a stored procedure
I am using SQL 2008R2 and I want to replace a view inside a stored procedure with a new stored procedure to return multiple variable values. Currently I am using the code below to get values for 4 different variables. I would rather get the 4 variables
from a stored procedure (which returns all of these 4 values and more) but not sure how to do so. Below is the code for getting the 4 variable values in my current sp.
DECLARE @TotalCarb real;
DECLARE @TotalPro real;
DECLARE @TotalFat real;
DECLARE @TotalLiquid real;
SELECT @TotalCarb = ISNULL(TotCarb,0),
@TotalPro = ISNULL(TotPro,0),
@TotalFat = ISNULL(TotFat,0),
@TotalLiquid = ISNULL(TotLiq,0)
FROM dbo.vw_ActualFoodTotals
WHERE (MealID = @MealID);You can replace the view with inline table valued user-defined function:
http://www.sqlusa.com/bestpractices/training/scripts/userdefinedfunction/
See example: SQL create INLINE table-valued function like a parametrized view
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Executing a Variable in a Stored Procedure containing an Update Statement
Hi,
I have created a Stored Procedure, it has one input parameter. Inside the Stored Procedure there are 5 other variables are declared, based on the input parameter 4 of these variables are populated.
Fifth variable is a a concatenation of text and some of these variables and creates a dynamic Update Statement. Once it is created I want to execute this variable but it is not executing.
Could someone please help me in knowing how to execute a variable within a stored procedure that contains an update statement.
Thanks for your help.
Thanks
Vineesh
vineesh1701If you have set up the variable so that it contains a valid sql update, it should work. For example, see below, which does do an update
use tempdb
go
Create Table #Test(i int);
Insert #Test(i) Values(1);
go
Create Procedure TestProc As
Begin
Declare @SQL nvarchar(250);
Set @SQL = 'Update #Test Set i = 2';
--Print @SQL;
Exec sp_executesql @SQL;
End
go
Exec TestProc
-- Test Result
Select * From #Test;
go
Drop Procedure TestProc;
go
Drop Table #Test;
One thing I would recommend while testing is that you print out or select the variable that contains the dynamic sql. (Like the above code where I have a print statement. That lets you see exactly what you are executing and if there is any problem
with the update command.
As Naomi said, to get anything more than general help, you will probably have to show us your code and the parameter values you are passing when you execute the stored proc.
Tom -
How to get an updatable ADODB Recordset from a Stored Procedure?
In VB6 I have this code to get a disconnected ADODB Recordset from a Oracle 9i database (the Oracle Client is 10g):
Dim conSQL As ADODB.Connection
Dim comSQL As ADODB.Command
Dim recSQL As ADODB.Recordset
Set conSQL = New ADODB.Connection
With conSQL
.ConnectionString = "Provider=OraOLEDB.Oracle;Password=<pwd>;Persist Security Info=True;User ID=<uid>;Data Source=<dsn>"
.CursorLocation = adUseClientBatch
.Open
End With
Set comSQL = New ADODB.Command
With comSQL
.ActiveConnection = conSQL
.CommandType = adCmdStoredProc
.CommandText = "P_PARAM.GETALLPARAM"
.Properties("PLSQLRSet").Value = True
End With
Set recSQL = New ADODB.Recordset
With recSQL
Set .Source = comSQL
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open
.ActiveConnection = Nothing
End With
The PL/SQL Procedure is returning a REF CURSOR like this:
PROCEDURE GetAllParam(op_PARAMRecCur IN OUT P_PARAM.PARAMRecCur)
IS
BEGIN
OPEN op_PARAMRecCur FOR
SELECT *
FROM PARAM
ORDER BY ANNPARAM DESC;
END GetAllParam;
When I try to update some values in the ADODB Recordset (still disconnected), I get the following error:
Err.Description: Multiple-step operation generated errors. Check each status value.
Err.Number: -2147217887 (80040E21)
Err.Source: Microsoft Cursor Engine
The following properties on the Command object doesn't change anything:
.Properties("IRowsetChange") = True
.Properties("Updatability") = 7
How can I get an updatable ADODB Recordset from a Stored Procedure?4 years later...
I was having then same problem.
Finally, I've found how to "touch" the requierd bits.
Obviously, it's hardcore, but since some stupid at microsoft cannot understand the use of a disconnected recordset in the real world, there is no other choice.
Reference: http://download.microsoft.com/downlo...MS-ADTG%5D.pdf
http://msdn.microsoft.com/en-us/library/cc221950.aspx
http://www.xtremevbtalk.com/showthread.php?t=165799
Solution (VB6):
<pre>
Dim Rst As Recordset
Rst.Open "select 1 as C1, '5CHARS' as C5, sysdate as C6, NVL(null,15) as C7, null as C8 from DUAL", yourconnection, adOpenKeyset, adLockBatchOptimistic
Set Rst.ActiveConnection = Nothing
Dim S As New ADODB.Stream
Rst.Save S, adPersistADTG
Rst.Close
Set Rst = Nothing
With S
'Debug.Print .Size
Dim Bytes() As Byte
Dim WordVal As Integer
Dim LongVal As Long
Bytes = .Read(2)
If Bytes(0) <> 1 Then Err.Raise 5, , "ADTG byte 0, se esperaba: 1 (header)"
.Position = 2 + Bytes(1)
Bytes = .Read(3)
If Bytes(0) <> 2 Then Err.Raise 5, , "ADTG byte 9, se esperaba: 2 (handler)"
LongVal = Bytes(1) + Bytes(2) * 256 ' handler size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 3 Then Err.Raise 5, , "ADTG, se esperaba: 3 (result descriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' result descriptor size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 16 Then Err.Raise 5, , "ADTG, se esperaba: 16 (adtgRecordSetContext)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 5 Then Err.Raise 5, , "ADTG, se esperaba: 5 (adtgTableDescriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(1)
If Bytes(0) <> 6 Then Err.Raise 5, , "ADTG, se esperaba: 6 (adtgTokenColumnDescriptor)"
Do ' For each Field
Bytes = .Read(2)
LongVal = Bytes(0) + Bytes(1) * 256 ' token size
Dim NextTokenPos As Long
NextTokenPos = .Position + LongVal
Dim PresenceMap As Long
Bytes = .Read(3)
PresenceMap = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(2)), 2))
Bytes = .Read(2) 'ColumnOrdinal
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
'Aca pueden venir: friendly_columnname, basetable_ordinal,basetab_column_ordinal,basetab_colname
If PresenceMap And &H800000 Then 'friendly_columnname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
If PresenceMap And &H400000 Then 'basetable_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H200000 Then 'basetab_column_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H100000 Then 'basetab_colname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
Bytes = .Read(2) 'adtgColumnDBType
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
Bytes = .Read(4) 'adtgColumnMaxLength
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Precision
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Scale
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Dim ColumnFlags() As Byte, NewFlag0 As Byte
ColumnFlags = .Read(1) 'DBCOLUMNFLAGS, First Byte only (DBCOLUMNFLAGS=4 bytes total)
NewFlag0 = ColumnFlags(0)
If (NewFlag0 And &H4) = 0 Then 'DBCOLUMNFLAGS_WRITE (bit 2) esta OFF
'Lo pongo en ON, ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 Or &H4)
End If
If (NewFlag0 And &H8) <> 0 Then 'DBCOLUMNFLAGS_WRITEUNKNOWN (bit 3) esta ON
'Lo pongo en OFF, ya que no me importa si NO sabes si se puede updatear no, yo lo se, no te preocupes
'ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 And Not &H8)
End If
If (NewFlag0 And &H20) <> 0 Then 'DBCOLUMNFLAGS_ISNULLABLE (bit 5) esta OFF
'Lo pongo en ON, ya que siendo un RST DESCONECTADO, si le quiero poner NULL, le pongo y listo
NewFlag0 = (NewFlag0 Or &H20)
End If
If NewFlag0 <> ColumnFlags(0) Then
ColumnFlags(0) = NewFlag0
.Position = .Position - 1
.Write ColumnFlags
End If
.Position = NextTokenPos
Bytes = .Read(1)
Loop While Bytes(0) = 6
'Reconstruyo el Rst desde el stream
S.Position = 0
Set Rst = New Recordset
Rst.Open S
End With
'TEST IT
On Error Resume Next
Rst!C1 = 15
Rst!C5 = "MUCHOS CHARS"
Rst!C7 = 23423
If Err.Number = 0 Then
MsgBox "OK"
Else
MsgBox Err.Description
End If
</pre> -
Retruring Multiple rows from a Stored Procedure
The Oracle JDBC documentation shows how to return a cursor pointer through the parameter list of a stored procedure allowing a Java program to use the cursor like a normal result set. I've tried it (using the thin driver) and it works fine - however, I'm having trouble getting this to work running the program under a Weblogic server (using their own JDBC implementation). So, I have two questions:
1) Has anyone had this problem before and solved it ??
2) Are there any other techniques for getting multiple rows back from the database without having to fire "raw" sql at it ?Hi
You could return not resultset but array, for example:
PACKAGE TEST:
type string_table is table of varchar2(80)
index by binary_integer;
function get_something (
something1 out string_table,
arraylength in number
) return number;
PACKAGE'S BODY:
function get_something (
something1 out string_table,
arraylength in number /** length of the array **/
) return number as
cursor C is
select something1, ...
from test_table;
pos number := 1;
begin
for position in C loop
exit when (pos > arraylength);
something1(pos) := position.something1;
pos := pos + 1;
end loop;
return (pos - 1);
end;
Of course in this example you need to know length of your array
(arraylength parameter), but you can avoid such problem, for
example, by using DBMS_SQL package (or dynamic SQL feature in
the Oracle8i).
Andrew
Mladen Gogala (guest) wrote:
: Phil Hildebrand (guest) wrote:
: : Is there a way that I can return multiple rows from a stored
: : procedure for function ?
: : Something like:
: : CREATE FUNCTION sp_get_children (my_nip IN port.nip_num%
TYPE)
: : RETURN my_nip
: : IS
: : CURSOR child_cur IS
: : SELECT nip_num
: : FROM logical_port
: : WHERE port_num = my_nip;
: : child_rec child_cur%rowtype;
: : BEGIN
: : FOR child_rec IN child_cur
: : LOOP
: : RETURN my_nip;
: : END LOOP;
: : END tmp_sp_get_children;
: : I know how to do it in Informix ( RETURN WITH RESUME ), but
: I'm
: : not running Informix ;)
: : Thanks,
: : Phil
: In contrast with Informix, SQL Server and Sybase, Oracle
: can not return a result set. the only workaround is to
: return the cursor variable as such.
null -
Calling stored procedure from a stored procedure
I have a stored procedure that accepts a customer prefix like "abc" and returns a customer document number like "abc-0021". (Thanks V Garcia)
This sp works when I call it from SQL Plus Worksheet.
But I need to call it from another stored procedure and store it in a local variable so that I can insert it into a table with the rest of the information.
This is what I have tried so far:
CREATE OR REPLACE PROCEDURE "SCHEMANAME"."SP_XXTESTXX" ( seq_name in
varchar2)
AS
id_out varchar(10);
BEGIN
execute SP_GET_NEXT_DOC_NUMBER(seq_name,:id_out);
print id_out;
END;but this will not compile. I get this error:
Line # = 8 Column # = 12 Error Text = PLS-00103: Encountered the symbol "SP_GET_NEXT_DOC_NUMBER" when expecting one of the following: := . ( @ % ; immediate The symbol ":=" was substituted for "SP_GET_NEXT_DOC_NUMBER" to continue.
Line # = 8 Column # = 41 Error Text = PLS-00049: bad bind variable 'ID_OUT'
Line # = 10 Column # = 10 Error Text = PLS-00103: Encountered the symbol "ID_OUT" when expecting one of the following: := . ( @ % ; The symbol ":=" was substituted for "ID_OUT" to continue.I think I got it.
CREATE OR REPLACE PROCEDURE "SCHEMANAME"."SP_XXTESTXX" ( seq_name in
varchar2)
AS
id_out varchar(10);
BEGIN
SP_GET_NEXT_DOC_NUMBER(seq_name,id_out);
dbms_output.put_line(id_out);
END;This works like I wanted it to do. -
Get a return value from a stored procedure.
hi all ,
i need to know where i am going wrong with the below code. I am trying to get a value from a stored procedure. the return type is int. The stored procedure works fine as i've debugged it. The variable have been declared correctly.
int n = 0;
proc = conn.prepareCall("{ ? = call SP_GETITEMCURRENTSOH(?,?) }");
proc.registerOutParameter(1, java.sql.Types.INTEGER);
proc.setString(1, locationCode);
proc.setString(2, itemCode);
proc.execute();
n = proc.getInt(1);thanksHi ayub_a,
According the [ *setString*|http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html#setString(java.lang.String,%20java.lang.String)] method of the [*CallableStatement*|http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html] interface, the first parameter must be a parameter name and not an ordinal position index !!!
Edit : I've just found out the solution, it must be :
int n = 0;
proc = conn.prepareCall("{ ? = call SP_GETITEMCURRENTSOH(?,?) }");
proc.registerOutParameter(1, java.sql.Types.INTEGER);
proc.setString(2, locationCode);
proc.setString(3, itemCode);
proc.execute();
n = proc.getInt(1);Edited by: Chicon on Jul 5, 2009 7:48 PM -
Call a function inside a package from a stored procedure
Hello:
I am kind of new to the stored procedure. Does anyone know how to call a function inside a package from another stored procedure?
I have a existing function (func_b) inside a package (pack_a) and it returns a cursor. I want to call this function from a stored procedure (proc_c) so that I use the data inside the cursor.
can I do the following in proc_c:
my_cursor1 SYS_REFCURSOR;
begin
my_cursor1 := exec pack_a.func_b
end
It will be very helpful if anyone can point me to any reading or example. Thank you very much for your information.guys:
Thank you for your information so far. I need some more help here. I was able to run the function in my stored procedure. However, I was not able to print the result on the screen to view the cursor result, although I am using dbms_output.put_line statement inside my stored procedure.
I use the following statement to execute my stored procedure on sql*plus. I can tell the stored procedure is executed successfully, but I did see anything printed:
DECLARE TEMP VARCHAR2(100);
BEGIN PROC_LAWS_CAD_NAME_SEARCH('LPD', 'TEST DEVICE ID', 'TEST LAST NAME', 'TEST FIRST NAME', 'F', '11112009', TEMP); END;
I tried to use 'set serveroutput on' and got the following error:
ERROR:
ORA-06502: PL/SQL: numeric or value error: host bind array too small
ORA-06512: at line 1
I am kind of confused now. thank you for your help.
Jack
Here is my procedure:
create or replace
PROCEDURE PROC_SEARCH
( AGENCY_ID IN VARCHAR2,
DEVICE_ID IN VARCHAR2,
L_NAME IN VARCHAR2,
F_NAME IN VARCHAR2,
SEX IN VARCHAR2,
DOB IN VARCHAR2,
CAD_NAME_SCH_RESULT_STR OUT VARCHAR2)
AS
v_agy_id varchar2(10);
v_device_id varchar2(20);
v_l_name varchar2(25);
v_f_name varchar2(15);
v_sex varchar2(1);
v_dob date;
-- this cursor is going to be used to store a list of warrant matching
-- name search criteria
cad_srch_cursor sys_refcursor;
objSrch SEARCH_RESULT_TEMP%ROWTYPE;
BEGIN
cad_srch_cursor := SEARCH_PKG.SEARCH('TESTING', 'TESTER', null, null,null, null, getPhonetic('TESTING'));
LOOP
FETCH cad_srch_cursor INTO objSrch;
EXIT WHEN cad_srch_cursor%NOTFOUND;
--insert into SEARCH_RESULT_TEMP (name_last) values (objSrch.name_last);
CAD_NAME_SCH_RESULT_STR := objSrch.name_last;
dbms_output.put_line('First:'||objSrch.name_first||':Last:'||objSrch.name_last||':Middle:'||objSrch.name_middle);
end LOOP;
END PROC_LAWS_SEARCH;
----------------------------------------- -
Problem in OUT Parameter in the stored procedure
Hi,
I have a problem in the OUT parameter of the stored procedure under the package. I encountered the error PLS-00306. Below are the codes.
Package
CREATE OR REPLACE package body test as
procedure sp_countries(rst OUT country_typ) as
sql_stmt VARCHAR2(300);
begin
sql_stmt := 'SELECT * FROM countries WHERE region_id = 1';
OPEN rst FOR sql_stmt;
end;
end test;
by the way. i declared the country_typ as this:
TYPE country_typ IS REF CURSOR;
Here is the code that will call this package:
declare
tst countries%ROWTYPE;
begin
test.sp_countries(tst);
dbms_output.put_line(tst.country_name);
end;Works for me. Although I had to use emp instead of your table:
SQL> create or replace
2 package test as
3 TYPE country_typ IS REF CURSOR;
4 procedure sp_countries(rst OUT country_typ);
5 end;
6 /
Package created.
SQL> CREATE OR REPLACE
2 package body test as
3 procedure sp_countries(rst OUT country_typ) as
4 sql_stmt VARCHAR2(300);
5 begin
6 sql_stmt := 'SELECT * FROM emp WHERE deptno = 20';
7 OPEN rst FOR sql_stmt;
8 end;
9 end test;
10 /
Package body created.
SQL> var tcur refcursor
SQL> exec test.sp_countries(:tcur);
PL/SQL procedure successfully completed.
SQL> print tcur
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
SQL> -
Invoking a UNIX shell command from Java stored procedure
The program below is suppose do send an email using UNIX mailx program. It works correctly when I compile it in UNIX and invoke it from the command line by sending an email to the given address.
I need this program to run as a stored procedure, however. I deploy it as such and try to invoke it. It prints the results correctly to the standard output. It does not send any emails, however. One other difference in execution is that when invoked from the command line, the program takes about a minute to return. When invoked as a stored procedure in PL/SQL program or SQL*Plus anonymous block, it returns immediately.
Why would mailx invocation not work from a stored procedure? Are there other ways to invoke mailx from PL/SQL?
Thank you.
Michael
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class MailUtility
public static void main(String[] args)
System.out.println(mailx("Hey, there", "Hello", "oracle@solaris10ora", 1));
* Sends a message using UNIX mailx command.
* @param message message contents
* @param subject message subject
* @param addressee message addressee
* @param display if greater than 0, display the command
* @return OS process return code
public static int mailx(String message, String subject,
String addressee, int display)
System.out.println("In mailx()");
try
String command =
"echo \"" + message + "\" | mailx -r [email protected]" + " -s \"" + subject + "\" " + addressee;
if (display > 0)
System.out.println(command);
try
Process process = Runtime.getRuntime().exec("/bin/bash");
BufferedWriter outCommand =
new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
outCommand.write(command, 0, command.length());
outCommand.newLine();
outCommand.write("exit", 0, 4);
outCommand.newLine();
outCommand.flush();
process.waitFor();
outCommand.close();
return process.exitValue();
catch (IOException e)
e.printStackTrace();
return -1;
catch (Exception e)
e.printStackTrace();
return -1;try adding the full explicit path to "mailx" in the command string that gets sent to Runtime. i would guess that the shell that gets spawned might not have a proper environment and thus mailx might not be found.
== sfisque -
Returning a table from a stored procedure
hi, i need to return a table from a stored procedure and show it, and come to this, but a don't know hoy to run it, so i don't know if it is right, can anyone help me?
uTable out objects_uptime%rowtype
as
begin
select * into uTable from objects_uptime;
end;well, i finally discovered how to do the trick
this is the code for the function:
CREATE OR REPLACE FUNCTION FN_GET_RECORDS RETURN UPTIME PIPELINED IS
CURSOR cUptime is select * from objects_uptime;
p refcur.refcur_t;
temp p%ROWTYPE;
temp2 OUPTIME := OUPTIME(null, null, null, null, null, null, null, null, null);
BEGIN
OPEN cUptime;
LOOP
FETCH cUptime into temp;
temp2.OBJ_NAME := temp.OBJ_NAME;
temp2.IP := temp.IP;
temp2.STATUS := temp.STATUS;
temp2.DOE := temp.DOE;
temp2.ENABLED := temp.ENABLED;
temp2.COMMENT00000 := temp.COMMENT00000;
temp2.USERID := temp.USERID;
temp2.OBJECTID := temp.OBJECTID;
temp2.MNTID := temp.MNTID;
pipe row(temp2);
EXIT WHEN cUptime%NOTFOUND;
END LOOP;
RETURN;
END FN_GET_RECORDS;
and this for the auxiliar package, object and table:
CREATE OR REPLACE PACKAGE REFCUR
as
TYPE refcur_t IS REF CURSOR RETURN objects_uptime%ROWTYPE;
end REFCUR;
CREATE OR REPLACE TYPE OUPTIME AS OBJECT ( "OBJ_NAME"
VARCHAR2(255), "IP" VARCHAR2(20), "STATUS" VARCHAR2(10),
"DOE" DATE, "ENABLED" NUMBER(10, 1), "COMMENT00000"
VARCHAR2(1000), "USERID" VARCHAR2(50), "OBJECTID" NUMBER(10,
1), "MNTID" NUMBER(10, 1) )
CREATE TYPE TUPTIME AS
TABLE OF OUPTIME
i call it this way:
select * from table(FN_GET_RECORDS ())
if anyone knows how to do the same in a shorter manner, tell me please.
thanks to everybody for the help. -
Hi,
How do I return two values from a
stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
Something like ?
CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
@intPeriod INT,
@strPeriod_Length NVARCHAR(1),
@dtStart NVARCHAR(8) OUTPUT,
@dtEnd NVARCHAR(8) OUTPUT
AS
then within the SSIS component; -
Kind Regards,
Kieran.
Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
Add a script task to check ssis variables values using,
Msgbox(Dts.Variables("User::strExtractStartDate").Value)
Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
Regards, RSingh
Maybe you are looking for
-
Replication house tells me my burned pcm and ac3 is mpeg
Sorry for the double post, just saw this audio section. I'm having a difficulty with my burned dvds apparently coming out mpeg audio. I exported from pp 1.0 a final mpeg video with PCM audio for my final dvd project. I used Encore CS3 to burn the dis
-
My control panel does not have flashlight,calculator or portrait lock
Control panel does not have flashlight,calculator or portrait lock
-
Is java 100% pure object oriented?
I am very confuse is java 100% pure object oriented language. bcoz 1)object oriented means everything should be in object but primitive data type is not object. 2) java don't support multiple inheritances which is one of the oop 's concept
-
I cannot update to the latest version of iTunes. Why not? My OS is Windows 7.
This is a new computer. It is 64 bits and I did get a note that said something about needing to change the installer to 64 bits. How do I do that?
-
Export Material and Price Data
Hi SAP Experts, I found two ways to implement a Master Material and Price Export to an external system, first with IDOC MATMAS01 and Idoc COND_A with an enhancement VKOE0001 PRICING CONDITION. Here I don't know how I can match a material with tht sal