Oracle function compiles successfully but throws error while executing PLS-00221: is not a procedure or is undefined - sql

I have simple oracle function
create or replace function abs.test_func(test_in in number)
return number
is
test_out number ;
BEGIN
test_out:=test_in;
RETURN test_out;
END;
if I compile it - it compiles successfully.
but when I run from PLSQL Developer SQL Window
BEGIN abs.test_func(5); END;
it I gets the following errors
ORA-06550: line1, column8;
PLS-00221: 'TEST_FUNC' is not a procedure or is undefined
ORA-06550: line1, column8;
PL/SQL: Statement ignored
What's wrong with my function ?

Your create function code looks good, however you are not invoking the function properly. A function returns something, that you must either select, assign, print, or evaluate.
Here are a few examples of valid function calls:
-- print the return value
begin
dbms_output.put_line(test_func(5));
end;
/
1 rows affected
dbms_output:
5
-- select the return value
select test_func(5) from dual;
| TEST_FUNC(5) |
| -----------: |
| 5 |
Demo on DB Fiddle

Related

How to call a user defined function using the 'CALL' statement?

I was going thru the Oracle documentation for the CALL statement. It is indicated there that the CALL statement can be used to call a user defined function by using INTO (not a function inside a package). I've tried loads of combinations but can't seem to get the right one. Can someone give me an example on how to do this? Thanks.
EDIT:
I've tried the example below in SQL Developer but i am getting an error.
variable x number;
call f(10) into :x;
I'm getting a bang in line 2 and the error:
SQL Error: ORA-01008: not all variables bound<br>
01008. 00000 - "not all variables bound"
From the Oracle documentation:
VARIABLE x VARCHAR2(25);
CALL warehouse_typ(456, 'Warehouse 456', 2236).ret_name()
INTO :x;
Another example:
create function f(n number) return number is
begin
return n * 2;
end;
SQL> variable x number;
SQL> call f(10) into :x;
Call completed.
SQL> print x;
X
----------
20

How to Convert Output of listagg() function into XMLTYPE

I have one stored Procedure P_FP_GET_PATTERN.I expect output in following format
PATTERN_ID |PATTERN_NAME | SHIFT
1 Pattern 1 A,B,C,B,A
2 Pattern 2 C,B,A,C
I'm getting this output in SYS_REFCURSOR ALL_RESULT_SET.I need to pass it in XML format.But the moment i put that output in ALL_RESULT_SET_XML which is my out parameter of stored procedure of XMLTYPE using ALL_RESULT_SET_XML:= XMLTYPE(ALL_RESULT_SET);
Im getting an error as
Error encountered: ORA-31061: XDB error: special char to escaped char conversion failed.
I`m getting this error due to column shown using LISTAGG() function.Anybody can please tell me how to handle this ?
My stored Procedure
create or replace
PROCEDURE P_FP_GET_PATTERN
(
ALL_RESULT_SET_XML OUT XMLTYPE,
P_MESSAGE_ALL OUT VARCHAR2
)
AS
V_ERROR VARCHAR2(2000);
ALL_RESULT_SET SYS_REFCURSOR;
BEGIN
OPEN ALL_RESULT_SET FOR
SELECT PM.PATTERN_ID ,PM.PATTERN_NAME,
LISTAGG(SM.SHIFT_NUMBER) WITHIN GROUP (ORDER BY PD.INSTANCE_DAY) "SHIFT"
FROM T_FP_PATTERN_MASTER PM,
T_FP_PATTERN_DETAILS PD,
T_FP_SHIFT_MASTER SM
WHERE SM.SHIFT_ID= PD.SHIFT_ID
AND PM.PATTERN_ID = PD.PATTERN_ID
GROUP BY PM.PATTERN_NAME,PM.PATTERN_ID;
--Adding output in XML output parameter
ALL_RESULT_SET_XML:= XMLTYPE(ALL_RESULT_SET);
EXCEPTION
WHEN OTHERS
THEN
V_ERROR := SUBSTR(SQLERRM,1,1000);
P_MESSAGE_ALL := 'Error encountered: '||V_ERROR ;
END;

Error: ORA-06550 in Oracle 10g

Here i have created a package,with package specification and package body,which contains a procedure which insert a row in table,package creation is successful but execution of that package is giving me error
ORA-06550
Package specification:
create or replace package pkgEmp --package specification created..
as
procedure insertEmp(eno number,name varchar2,job varchar2,mgr varchar2,salary number);
end pkgEmp;
package body:
create or replace package body pkgEmp
as
procedure insertEmp(eno number,name varchar2,job varchar2,mgr varchar2,salary number)
is
begin
insert into emp values(eno,name,job,mgr,salary);
end insertEmp;
end pkgEmp;
Exeuting procedure insertEmp:
begin
pkgEmp.insertEmp(&eno,&name,&job,&mgr,&salary); --i m trying to get data in run time.
End;
and output:
ORA-06550: line 2, column 18:
PLS-00103: Encountered the symbol "&" when expecting one of the following:
( ) - + case mod new not null others
table avg count current exists max min prior sql stddev sum
variance execute multiset the both leading trailing forall
merge year month DAY_ hour minute second timezone_hour
timezone_minute timezone_region timezone_abbr time timestamp
interval date
1. begin
2. pkgEmp.insertEmp(&eno,&name,&job,&mgr,&salary);
3. End;
Why I am not able to get data from User,I m using SQL*Plus
I think you need to put parameters in 'single quotes' like '&name' where the datatype is non-integer.
Thanks,
Aditya

Compilation error in Oracle PL/SQL

I have been staring at this hours trying to figure out why it won't run, and cannot see any syntax error which should stop this from compiling, but I am nonetheless getting the following errors:
Error(6,1): PL/SQL: SQL Statement ignored
Error(22,7): PL/SQL: ORA-00933: SQL command not properly ended
The function I am trying to create is as follows:
create or replace function caps_get_Uoffer_count_BD(ayrc in varchar2
,mcrc in varchar2)
return number
is
app_count number;
begin
select count(*)
from
(select distinct cap.cap_stuc,cap.cap_apfs , cap.cap_seqn from
intuit.srs_cap cap
,intuit.srs_apf apf
,intuit.srs_ioi ioi
where cap.cap_ayrc = ayrc
and cap.cap_mcrc = mcrc
and apf.apf_stuc = cap.cap_stuc
and apf.apf_seqn = cap.cap_apfs
and apf.apf_recd <= to_date('1501'||substr(ayrc,1,4),'DDMMYYYY')
and cap.cap_stuc = ioi.ioi_stuc
and cap.cap_mcrc = ioi.ioi_mcrc
and ioi.ioi_iodc ='PAPERLESS'
and cap.cap_stac like 'A%'
and cap.cap_idrc in ('U','UF','UI','UD','CFU','CFUF','CIUI','CIUF','CIUD','CIU','CFUI','CFUD'))
return(app_count);
end;
Database is Oracle 11g. Can anyone help?
Many thanks in advance

I see the error but the account is valid

SQL> CREATE or REPLACE FUNCTION custord (custNo IN number)
2 RETURN NUMBER
3 IS cust_tot NUMBER(11,2);
4 BEGIN
5 SELECT sum(cust_total_field)
6 INTO cust_tot
7 FROM ord
8 WHERE cust_number_field=custNo;
9 RETURN(cust_tot);
10 END;
11 /
Warning: Function created with compilation errors.
SQL> begin
2 dbms_output.put_line('customer 102 total is ' || custord(102));
3 end;
4 /
dbms_output.put_line('customer 102 total is ' || custord(102));
*
ERROR at line 2:
ORA-06550: line 2, column 52:
PLS-00905: object CIS605.CUSTORD is invalid
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
SQL>
I see the error but object cis605 is valid. Any ideas what I am missing?
Using the ORD table create a stored function called custord that will use a customer id (CUSTID) that will return the sum of the specified customer id TOTAL field.
When your function has been stored run the following SQL:
begin
dbms_output.put_line('customer 102 total is ' || custord(102));
end;
Your output should look like:
Results
Explain
Describe
Saved SQL
History
customer 102 total is 27775.5
Statement processed.
Try
SHOW ERRORS FUNCTION custord
Your custord function was created with compilation errors, so there is something wrong with it. This is why you're getting the object CIS605.CUSTORD is invalid error.