Trouble referencing return values of a Function in Stored Procedure
Hello all,
I have the following Function and Stored Procedure (simplified for this post). The error I am getting is in the SELECT, WHERE clause of the UPDATE command. My function is returning a sys_refcursor and I am trying to reference column names but keep getting the error
ORA-00904: "PUBLISHEDDOCVERSIONID": invalid identifier
What am I doing wrong?
Function
CREATE OR REPLACE FUNCTION &HKDB_Schema_Name..QueryKnowdeDocVersion(aKGID int)
RETURN sys_refcursor
IS
aCur sys_refcursor;
BEGIN
OPEN aCur FOR
SELECT pkd.KnowdeID as "PublishedKnowdeID", pkd.DocumentID as "PublishedDocID", pkd.VersionID as "PublishedDocVersionID"
FROM KnowdeDocument pkd
WHERE pkd.KGID = aKGID;
RETURN aCur;
END;Stored Procedure
UPDATE KnowdeDocument
SET DocumentID = (SELECT PublishedDocID FROM (SELECT QueryKnowdeDocVersion(aKGID, aPublishedKGID, aTextVersionID) FROM DUAL)
WHERE PublishedKnowdeID = KnowdeDocument.KnowdeID
AND PublishedDocID = KnowdeDocument.DocumentID
AND ((PublishedDocVersionID is NULL and KnowdeDocument.VersionID is NULL) OR (PublishedDocVersionID is not NULL AND
PublishedDocVersionID = KnowdeDocument.VersionID)))Regards,
Toby
Hi redeye,
Your select is from:
(select queryknowdedocversion(akgid
,apublishedkgid
,atextversionid)
from dual)This has no publisheddocversionid. Unfortunately I cannot figure out what you are trying to do with that ref_cursor.
Edit:
Or perhaps publisheddocversionid is a column in KnowdeDocument? Could this be case sensitive as well? (Bad idea to use quotations when naming things)
Regards
Peter
Edited by: Peter on Aug 24, 2009 3:39 AM
Similar Messages
-
Getting Return values from RFC function call with visual basic
Hi,
I am creating a sample app to connect to a SAP system which call its RFC functions created with ABAP. It was known that the function will return more than 1 return values.
SAP Function name ==> "ZFMTP_RFC_GET_RESULT"
Export parameters (to SAP):
- Student Name [char 10] ==> "STUNAME"
- Student ID [char 20] ==> "STUID"
Return values (From SAP):
- Results [char 10] ==> "RESULT"
- Remarks [char 200] ==> "REMARKS"
i have managed to get sample codes for connecting and call a RFC function with vb but they only get a return value. How do i retrieve multiple return values like the above function "RESULT" and "REMARKS"?
Here's my vb code to accessing the function
Dim R3 As Object
Dim FBFunc As Object
Dim returnFunc As Boolean
Dim connected As Boolean
R3 = CreateObject("SAP.Functions")
R3.Connection.Client = "000"
R3.Connection.User = "BCUSER"
R3.Connection.Password = "minisap"
R3.Connection.Language = "DE"
R3.Connection.System = "dtsystem"
R3.Connection.Applicationserver = "xxx.xxx.xxx.xxx"
connected = R3.Connection.Logon(0, True)
If connected <> True Then
MsgBox("Unable to connect to SAP")
End If
FBFunc = R3.add("ZFMTP_RFC_GET_RESULT")
FBFunc.exports("STUNAME") = "Jonny"
FBFunc.exports("STUID") = "12345"
returnFunc = FBFunc.Call() <<== How do i get the return value? or RESULT and REMARKS of the RFC Function?
thanks alot.
Edited by: Eugene Tan on Mar 4, 2008 7:17 AMHi Gregor,
Thanks for the link....i am having some doubts with the codes, hope you can clarify them for me if you know the codes..
Below is the code snippet.
Set impReturn = CHPASS_FN.Imports("RETURN") <<=== is RETURN the standard keyword to get a return object?
expPassword.Value = currpass
expNewPass.Value = newpass
expFillRet.Value = "1"
''' Call change password function
If CHPASS_FN.Call = True Then
outFile.Write (", Called Function")
Message = impReturn("MESSAGE") <<==== So if i have 3 return values..i just replace with the return value variable names?
outFile.WriteLine " : " & Message
Else
outFile.Write (", Call to function failed")
End If
thanks alot...all your help is very appreciated. -
Problem loading images from a return value of a function
hello, I write because I uin problem in loading images from a return value of a function.
I created a database with a field "image" of type string, where I put the physical address of the image. I have written like this: {__DIR__ }foto.jpg
Place the code, so you understand better
function imageViewImage(): javafx.scene.image.Image {
connetti();
lass.forName(driverName);
con = DriverManager.getConnection(url,user,"");
stmt = con.createStatement();
var richiesta:String = "SELECT image from viaggio WHERE id_viaggio=7";
rs1 = stmt.executeQuery(richiesta);
var result :String;
rs1.next();
risultato = rs1.getString("image");
JOptionPane.showMessageDialog(null, result);
var imagez = Image{
url:"{result}";
return imagez;
The image is in the source code package
First I connect to the database, run the query and I take the contents of the image.
Can anyone help me?
Is right to put in the database {__DIR__} foto.jpg or do I put only foto.jpg?Hello unkus_nob,
I would rather suggest you to save only filename of that image like "foto.jpg" in database. And just concat it with the String variable containing "{__DIR__}".
Actually the javafx compiler converts the {__DIR__} to the existing class directory path something like : "jar:file:/..../".
var currentDir ="{__DIR__}";
risultato = "{currentDir}{rs1.getString("immagine"})";
var image = Image{
url:risultato
return image;--NARAYAN G. -
Hello,
I'm using RPAD function in stored procedure 4 times in one query and then inserting to another table. from dm_exec_sql_text table I see that every time that procedure approach to Rpad function it's open and closing in the and so it's open and closing
function 4 times per one row, If I have 1000 rows to insert the function will open and close 4000 times and it's very slow.
My question if there is some way to change this functionality of open / close function every time ?
Thank You
DanielYes, avoid using UDF , means especially a scalar udf... See how you can re-write a scalar udf as table valued udf.
http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/05/23/reuse-your-code-with-cross-apply.aspx
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Create a View, function or stored procedure for query?
Hi All,
I like to know how I can create a view or function for the query below. If its going to be a function or stored procedure will I be able to union it with another view?
DECLARE
@BegDate DATE,
@EndDate DATE
SELECT
@BegDate = MIN(vl.VoidStartDate),
@EndDate = MAX(vl.LetDate)
FROM #VoidLoss vl
;WITH d(d) AS (
SELECT TOP (DATEDIFF(dd, @BegDate, @EndDate))
DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1, @BegDate)
FROM sys.all_objects o
), cal AS (
SELECT
d.d,
MONTH(d.d) AS m,
YEAR(d.d) AS y
FROM d
SELECT
vl.History_IND,
vl.PropCode,
vl.VoidCategory,
vl.ControlGroup,
CASE WHEN vl.VoidStartDate < MIN(cal.d) THEN MIN(cal.d) ELSE vl.VoidStartDate END AS VoidStartDate,
CASE WHEN vl.LetDate > MAX(cal.d) THEN MAX(cal.d) ELSE vl.LetDate END AS LetDate,
vl.MarketRent,
DATENAME(mm, CAST('1900-' + CAST(cal.m AS VARCHAR(2)) + '-1' AS DATE)) AS [Month],
cal.y AS [Year],
COUNT(*) AS DaysVoid,
COUNT(*) * vl.MarketRent AS VoidLoss
FROM
#VoidLoss vl
JOIN cal
ON cal.d BETWEEN DATEADD(dd, 1, vl.VoidStartDate) AND vl.LetDate
GROUP BY
vl.History_IND,
vl.PropCode,
vl.VoidCategory,
vl.ControlGroup,
vl.VoidStartDate,
vl.LetDate,
vl.MarketRent,
cal.m,
cal.y
ORDER BY
vl.History_IND,
vl.PropCode,
vl.VoidStartDate
ThanksA view or an inline-function is a single query, so this part does not fit in:
DECLARE
@BegDate DATE,
@EndDate DATE
SELECT
@BegDate = MIN(vl.VoidStartDate),
@EndDate = MAX(vl.LetDate)
FROM #VoidLoss vl
And you cannot have it multi-statement function either, since you cannot refer to temp tables in such a function. In any case, using a multi-statement function in a view definition or nest it in another function definition is likely to be a performance disaster.
The sole alternative that remains as long as you have the temp table is a stored procedure. You cannot use a stored procedure in a view or a function.
Erland Sommarskog, SQL Server MVP, [email protected] -
Hi ,
I use Oracle 10g and forms10g.
I have written a db packaged function such as:
function fnc_ipologismos_xiliometron(code_poleis_apo_var in varchar2,code_poleis_pros_var in varchar2)
return number
is
apostasi_var ref_apostaseis_poleon.apostasi%type;
onomasia_pol_apo_var ref_poleis.onomasia%type;
onomasia_pol_pros_var ref_poleis.onomasia%type;
begin
begin
select onomasia into onomasia_pol_apo_var
from ref_poleis
where code_poleis=code_poleis_apo_var;
end;
begin
select onomasia into onomasia_pol_pros_var
from ref_poleis
where code_poleis=code_poleis_pros_var;
end;
begin
select apostasi into apostasi_var
from ref_apostaseis_poleon
where code_poleis_apo=code_poleis_apo_var and code_poleis_pros=code_poleis_pros_var;
exception
when no_data_found
then
apostasi_var:=0;
return apostasi_var;
raise_application_error(-20015,'a message');
--return apostasi_var;
end; return apostasi_var;
end;The problem is that when the exception written above (in bold) returns 0 and exits the function.... whereas i want this value to be returned as well as the message in the raise_application_error....
I call this function in WHEN-VALIDATE-ITEM of a block item... such as:
if pkg_mod3_general.fnc_ipologismos_xiliometron
(:mod3_entoli_metakinisis.code_poleis_apo_type_id,:mod3_entoli_metakinisis.code_poleis_type_id)=0
and :mod3_entoli_metakinisis.seq_code_meso_metakin_type_id=2
then
raise form_trigger_failure;
end if; When the above condition is true then no message is displayed and the cursor sticks to the item(as the raise_application_error in the db packaged function is after the exit of the function) and when the condition is false then no message is displayed again ... as expected.....
How is it get the desired result.....- get the message from the raise_application_error and the function returns 0.....?????
Many thanks,
Simonyou cannot RETURN and RAISE a function.
RETURN ends the function immediately
RAISE ends the program unit and jumps in the EXCEPTION-Handler, if it exists. Else the function ends -
How to Access the Return Value of a Function
Hi,
How do I access the return value when calling an Oracle function from .NET using Oracle.DataAccess.Client? The function returns an integer of 0, 1 or 99.
Dim db_command_oracle As New OracleCommand()
db_command_oracle.Connection = db_connection_oracle
db_command_oracle.CommandType = CommandType.StoredProcedure
db_command_oracle.CommandText = "swsarsi.import_appointments"
Dim ret_value As New OracleParameter()
ret_value.OracleDbType = OracleDbType.Int32
ret_value.Direction = ParameterDirection.ReturnValue
ret_value.Size = 2
ret_value.OracleDbType = OracleDbType.Int32
db_command_oracle.Parameters.Add(ret_value)
Dim IN_student_id As New OracleParameter()
IN_student_id.OracleDbType = OracleDbType.Varchar2
IN_student_id.Direction = ParameterDirection.Input
IN_student_id.Size = 10
IN_student_id.Value = student_id
db_command_oracle.Parameters.Add(IN_student_id)
db_command_oracle.ExecuteNonQuery()
messagebox.show(ret_value) ?????Your ODP.NET code looks correct. What error are you seeing?
One thing that will definitely generate an error is that .NET message boxes require that strings be displayed. ret_value is a parameter object. You need to access its value and convert it to a string. At a minimum, you need to change that. -
Lookup return value string as Function
The only way which I know of is to define mapping parameters with the IsExprVar flag checked; then you can provide each individual business rule for one session run, source all records which have to be processed by this particular business rule and process them, and repeat the whole process until all business rules have been used. Regards,Nico
Hi,I have a requirement to load close to 100 files. Each files has different business rules. Business Rules are saved in tableI'm planning to create one stage mapping and use the lookup to read the business rule apply them, but INFA is treating the look up return values as string and not as function.. Is there a way to make INFA treat them as function Eg: Business Rule : col1|| col2 INFA load them as "col1||col2", instead of subsituting col1 value Thanks
-
Function calling stored procedure that returns a cursor into a LOV
Hello,
Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?Hi Vikas,
Actually, I just found another posting that shows how to do what I'm looking for:
Re: Filling a LOV with a cursor
Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
Laura -
Calling Function in Stored Procedure
Hi all,
I've created table below,
CREATE TABLE TEST
ID NUMBER(3) NOT NULL,
selectcode VARCHAR2(10),
value_use VARCHAR2(10),
bin_no NUMBER(10),
markup VARCHAR2(40),
descr VARCHAR2(100),
value_imp VARCHAR2(90)
create sequence idseq;
insert into test values (idseq.nextval,'rel','C1',1,'master','test1');
insert into test values (idseq.nextval,'rel','C1',1,'masterdir','test2');
insert into test values (idseq.nextval,'rel','C1',2,'master','test3');
insert into test values (idseq.nextval,'rel','C2',2,'masterdir','test4');
insert into test values (idseq.nextval,'rel','C2',2,'master','test5');
insert into test values (idseq.nextval,'rel1','C2',1,'master','test6');
insert into test values (idseq.nextval,'rel1','C2',1,'masterdir','test7');
select * from test;
ID SELECTCODE VALUE_USE BIN_NO MARKUP DESCR
1 rel C1 1 master test1
2 rel C1 1 masterdir test2
3 rel C1 2 master test3
4 rel C2 2 masterdir test4
5 rel C2 2 master test5
6 rel1 C2 1 master test6
7 rel1 C2 1 masterdir test6There is an existing function called valcon which returns data for value_imp based on value_use and markup in the table.
SQL>select valcon ('C1','master',' ','VALUE',' ') output from dual;
OUTPUT
Value In County
I created a stored procedure, to insert values to this table using this function.. But I'm not sure how to pass the value inside the function..
CREATE OR REPLACE PROCEDURE test_sp
( in_selectcode IN varchar2,
in_valueuse IN varchar2
AS
cursor val_cur is
select *
from test
where ....;
TYPE val_typ IS TABLE OF val_cur%ROWTYPE;
val_arr val_typ;
begin
open cursor..
fetch cursor into val_arr;
FOR ..
LOOP
insert into test (id, selectcode, value_use, selectval,value_imp)
select id_seq.nextval, in_selectcode, 'C1', Nvl2(Trim(in_selectcode),'Y','N'),
valcon ('val_arr.value_use','val_arr.markup',' ','VALUE',' ')
from dual;
end loop;
close cursor;
end;
end test_sp
/ Since i'm using an array, can you please tell me how I can pass 'val_arr.value_use' as a string in the function? I researched a lot to find this, but I couldnt find how I can do this.
Thank youI've used an update query to update test.bin_no in a sequence for the same selectcode and value_use. But I'm trying to see if I can do this within the insert query so I dont have to duplicate the work with one insert and one update.
The procedure below works with update query:
CREATE TABLE TEST
ID NUMBER(3) NOT NULL,
selectcode VARCHAR2(10),
value_use VARCHAR2(10),
bin_no NUMBER(10),
markup VARCHAR2(40),
descr VARCHAR2(100),
value_imp VARCHAR2(90)
create sequence idseq;
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel','C1',1,'Y');
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel','C1',1,'Y');
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel','C1',2,'Y');
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel','C2',2,'Y');
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel','C2',2,'Y');
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel1','C2',1,'Y');
insert into test (id,selectcode,value_use,bin_no,value_imp) values (idseq.nextval,'rel1','C2',1,'Y');
select * from test;
ID SELECTCODE VALUE_USE BIN_NO VALUE_IMP
1 rel C1 1 Y
2 rel C1 2 Y
3 rel C1 2 Y
4 rel C2 2 Y
5 rel C2 2 Y
6 rel1 C2 1 Y
7 rel1 C2 1 Y
CREATE OR REPLACE PROCEDURE test_sp (in_selectcode IN VARCHAR2,
in_valueuse IN VARCHAR2
) AS
msg VARCHAR2 (4000);
BEGIN
INSERT INTO test (id, selectcode, value_use, bin_no, selectval, value_imp
SELECT id_seq.NEXTVAL,
in_selectcode,
'C1',
bin_no,
NVL2 (TRIM (in_selectcode), 'Y', 'N'),
valcon (value_use, markup, ' ', 'VALUE', ' ')
FROM kn_job
WHERE scode= in_selectcode;
update test t
set t.bin_no = (select t1.r from
(select rowid, ROW_NUMBER() OVER(PARTITION BY in_selectcode, in_valueuse ORDER BY id asc) r from test) t1
where t.rowid=t1.rowid);
end test_sp
select * from test;
ID SELECTCODE VALUE_USE BIN_NO VALUE_IMP
1 rel C1 1 Y
2 rel C1 2 Y
3 rel C1 3 Y
4 rel C2 1 Y
5 rel C2 2 Y
6 rel1 C2 1 Y
7 rel1 C2 2 Y But is it possible to do this without an update query? Updating bin_no in a sequence for selectcode,value_use?
Thanks -
How to call CLOB to BLOB conversion function within stored procedure?
I have a tiny APEX application from which I need to be able to print. I’ve used these two resources: (Is there an inexpensive APEX report printer for invoices/checks/statements? and http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA)
I guess that in order to be able to download the RTF document stored in CLOB, I need to convert it into BLOB. I’ve found this function for this purpose on Oracle forums:
CREATE OR REPLACE FUNCTION c2b( c IN CLOB ) RETURN BLOB
-- typecasts CLOB to BLOB (binary conversion)
IS
pos PLS_INTEGER := 1;
buffer RAW( 32767 );
res BLOB;
lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
BEGIN
DBMS_LOB.createTemporary( res, TRUE );
DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
LOOP
buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
IF UTL_RAW.LENGTH( buffer ) > 0
THEN
DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
END IF;
pos := pos + 16000;
EXIT WHEN pos > lob_len;
END LOOP;
RETURN res; -- res is OPEN here
END c2b;And I am trying to use it in the modified download procedure that I also have found on Oracle forums:
CREATE OR REPLACE PROCEDURE DOWNLOAD_WO(v_id IN NUMBER)
AS
v_mime VARCHAR2(48);
v_length NUMBER;
v_file_name VARCHAR2(2000):= 'WO_Download.rtf';
lob_loc CLOB;
v_blob BLOB;
v_company jobs_vw.company%TYPE;
v_project jobs_vw.project%TYPE;
v_description jobs_vw.description%TYPE;
v_date_ jobs_vw.date_%TYPE;
v_job_no jobs_vw.job_no%TYPE;
v_apqwo jobs_vw.apqwo%TYPE;
-- v_mime VARCHAR2(48) := 'application/msword';
BEGIN
SELECT mime_type, report, DBMS_LOB.GETLENGTH(report)
INTO v_mime,lob_loc,v_length
FROM report_layouts
WHERE rl_id = 22332925279634283;
-- JOB_VW record:
SELECT job_no
,date_
,description
,apqwo
,project
,company
INTO v_job_no
,v_date_
,v_description
,v_apqwo
,v_project
,v_company
FROM jobs_vw
WHERE id = 214;
-- Replace holders with actual values:
lob_loc := REPLACE(lob_loc, '#COMPANY#', v_company);
lob_loc := REPLACE(lob_loc, '#PROJECT#', v_project);
lob_loc := REPLACE(lob_loc, '#DESCRIPTION#', v_description);
lob_loc := REPLACE(lob_loc, '#DATE_#', TO_CHAR(v_date_, 'DD/MM/YYYY'));
lob_loc := REPLACE(lob_loc, '#JOB_NO#', v_job_no);
lob_loc := REPLACE(lob_loc, '#APQWO#', v_apqwo);
-- set up HTTP header
-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
-- set the size so the browser knows how much to download
htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
-- wpg_docload.download_file( Lob_loc );
v_blob := c2b(lob_loc);
wpg_docload.download_file( v_blob );
end DOWNLOAD_WO;
/Unfortunately when I try to compile the download_wo stored procedure I am getting this error:
Error at line 64: PL/SQL: Statement ignoredThe 64th line is:
v_blob := c2b(lob_loc);How should I correctly call c2b within download_wo? Any advice is greatly appreciated.
Thank you for your time.
DanielHello there,
Well, its invalid :(
Object C2B is Invalid. I didn't know since when I run the create ... function, I only get this feedback:
Statement processed.
0.19 secondsI am investigating.
Daniel -
Return national language strings from java stored procedures
Hi, all.
How does i can return String which contains national characters from java stored procedure? I.e. convert UTF java string to national language of database. It's does not processing automatically (why?).
declaration of procedure:
CREATE OR REPLACE FUNCTION TestNLSString RETURN VARCHAR2
AS
LANGUAGE JAVA
NAME 'test.SomeClass.getNLSString() return java.lang.String';
SELECT TestNLSString AS X FROM DUAL;
X
iiiii
OS: Windows 2000 Server
Oracle Server version: Oracle 8.1.7.1.4Ok. I had a specific problem.
I want to use java stored procedure (function) to make a connection to remote db using supplied connection parameters make some quieries there end return results in a form of structured data - object.
I have defined an object type in a database where the function will reside. I granted execute privilege to public user on this type, made public synonyms to both, the object type and the function, so anybody connected to the same database would have an access to this functionality.
I supposed that if I supply connection parameters for some other user but the same database when running the function, everything should go smooth. Yeah.
My java code executed ok: it made a connection to the db with some x user, it resolved object type descriptor given (oracle.sql.StructDescriptor), but pl/sql wrapper function reported the error I've mentioned. If I executed the function giving it the connection parameters for same account as where object type was declared, everything went fine.
My final solution is:
Make TWO! connection in java code: 1st for ("jdbc:default:connection:"), 2nd for remote database account.
Use first connection to construct oracle.sql.StructDescriptor
Use second connection to retreive data from remote db -
Difference between Function and Stored Procedure
Hi guys, i don't understand the exact difference between a function and a stored procedure. I did lot of google but still. Can somebody explain in simple words. Thanks.
Hi,
Here's an example of a user-defined function:
CREATE OR REPLACE FUNCTION factorial
( in_num IN PLS_INTEGER
RETURN PLS_INTEGER
DETERMINISTIC
IS
BEGIN
IF in_num IS NULL
THEN
RETURN NULL;
ELSIF in_num <= 1
THEN
RETURN 1;
ELSE
RETURN in_num * factorial (in_num - 1);
END IF;
END factorial;
SHOW ERRORSThis function retruns an integer. You can use the function (or, more properly, the integer that it returns) anywhere an integer expression is allowed.
For example
SELECT ROWNUM
, factorial (ROWNUM) AS f
, loc
, SUBSTR ( loc
, 1
, factorial (ROWNUM)
) AS s
FROM scott.dept;Output:
` ROWNUM F LOC S
1 1 NEW YORK N
2 2 DALLAS DA
3 6 CHICAGO CHICAG
4 24 BOSTON BOSTON -
Retrive a new sequence value from a table using Stored Procedure
Dear experts
i have written the following stored procedure, but i want this to return itemid to the environment. Please help as i am absolutely new to oracle.
create or replace procedure "SP_ITEMS"
(vitem IN VARCHAR2,
vqty IN NUMBER,
vrate IN NUMBER)
is
begin
INSERT INTO ITEMS (item,qty,rate)
VALUES (vitem,vqty,vrate);
end;
Thanks
With regards
Manish SawjianiIf you want a column to be automatically populated with a sequence, then you need to create a sequence, and create a trigger to populate the column with the sequence. You can use the returning clause in a select statement to return the value of the inserted sequence. You can do this with just sql or you can put it in a procedure. I have demonstrated both below. This is a general sql and pl/sql problem, not something specific to the Express Edition, so please post future such questions in the sql and pl/sql discussion group instead.
SCOTT@10gXE> CREATE TABLE items
2 (itemid NUMBER,
3 item VARCHAR2 (50),
4 qty NUMBER (10, 3),
5 rate NUMBER (10, 3))
6 /
Table created.
SCOTT@10gXE> CREATE SEQUENCE item_sequence
2 /
Sequence created.
SCOTT@10gXE> CREATE OR REPLACE TRIGGER items_bir
2 BEFORE INSERT ON items
3 FOR EACH ROW
4 BEGIN
5 SELECT item_sequence.NEXTVAL
6 INTO :NEW.itemid
7 FROM DUAL;
8 END items_bir;
9 /
Trigger created.
SCOTT@10gXE> SHOW ERRORS
No errors.
SCOTT@10gXE> VARIABLE g_itemid NUMBER
SCOTT@10gXE> INSERT INTO items (item, qty, rate)
2 VALUES ('item1', 2, 3)
3 RETURNING itemid INTO :g_itemid
4 /
1 row created.
SCOTT@10gXE> PRINT g_itemid
G_ITEMID
1
SCOTT@10gXE> CREATE OR REPLACE PROCEDURE sp_items
2 (p_item IN VARCHAR2,
3 p_qty IN NUMBER,
4 p_rate IN NUMBER,
5 p_itemid OUT NUMBER)
6 AS
7 BEGIN
8 INSERT INTO ITEMS (item, qty, rate)
9 VALUES (p_item, p_qty, p_rate)
10 RETURNING itemid INTO p_itemid;
11 END sp_items;
12 /
Procedure created.
SCOTT@10gXE> SHOW ERRORS
No errors.
SCOTT@10gXE> EXECUTE sp_items ('item2', 3, 4, :g_itemid)
PL/SQL procedure successfully completed.
SCOTT@10gXE> PRINT g_itemid
G_ITEMID
2
SCOTT@10gXE> SELECT * FROM items
2 /
ITEMID ITEM QTY RATE
1 item1 2 3
2 item2 3 4
2 rows selected.
SCOTT@10gXE> -
How to return a VARRAY datatype in a stored procedure
I have declared a type using
create type list1 as VARRAY(1000) of number(5);
I want to return a list of values from a stored procedure. I created a stored procedure using
create procedure getlist(mylist OUT list1) is
begin
end;
The type and procedure creation was successful. But when I call this stored procedure from a PL/SQL module I get the following error.
ORA-06531: Reference to uninitialized collection
The PL/SQl module is
declare
s1 list1(1,2);
begin
getlist(s1);
end;
I want the procedure to return around 1000 values. Any solutions.
Mohan
null<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by MOHAN [email protected]:
I have declared a type using
create type list1 as VARRAY(1000) of number(5);
I want to return a list of values from a stored procedure. I created a stored procedure using
create procedure getlist(mylist OUT list1) is
begin
end;
The type and procedure creation was successful. But when I call this stored procedure from a PL/SQL module I get the following error.
ORA-06531: Reference to uninitialized collection
The PL/SQl module is
declare
s1 list1(1,2);
begin
getlist(s1);
end;
I want the procedure to return around 1000 values. Any solutions.
Mohan<HR></BLOCKQUOTE>
I am also having the same problem ..plzz help me someone
null
Maybe you are looking for
-
Hi, Are there any Oracle documents listing the standard process's for each module? Or Process flow diagrams? Many thanks
-
Bonjour, j'avais installé la suite adobe CS5 et acrobat 9 pro sur mon ordinateur mac. J'ai acheté un nouvel ordinateur et j'ai donc voulu transférér les licences sur mon nouvel ordinateur. le transfert a bien fonctionné pour la CS5 design premium mai
-
I rented a movie and the download was interrupted. Where can I find it again to resume the download?
-
How do I redownload elements to my new computer, I have the key and S/N?
How do I redownload elements to my new computer, I have the key and S/N?
-
Repairing external drive when improperly dismounted
not sure if anything can be done. i screwed up- i unplugged the drive while the computer was restarting, to plug it into a more secure power source (through battery backup). anyhow, i know i should have unmounted it first and i was stupid- it was a h