I'm currently trying to execute a stored procedure in Oracle PL SQL. I keep running into the same error for the below with execution.
I've tried both execution with the same error
SET SERVEROUTPUT ON;
EXEC get_phone(200.00,500.00);
OR
SET SERVEROUTPUT ON;
DECLARE
c_minprice products.price%type;
c_maxprice products.price%type;
BEGIN
c_minprice := get_phone(200);
c_maxprice := get_phone(500);
END;
ERROR from executing the above:
c_minprice := get_phone(200);
*
ERROR at line 5:
ORA-06550: line 5, column 15:
PLS-00306: wrong number or types of arguments in call to 'GET_PHONE'
ORA-06550: line 5, column 1:
PL/SQL: Statement ignored
ORA-06550: line 6, column 15:
PLS-00306: wrong number or types of arguments in call to 'GET_PHONE'
ORA-06550: line 6, column 1:
PL/SQL: Statement ignored
****Sample Snip-its form my code:
CREATE OR REPLACE PROCEDURE get_phone
(
c_minprice IN products.price%type,
c_maxprice IN products.price%type,
i_result OUT VARCHAR2
) AS
--Checking if starting price range is valid or not
IF c_minprice IS NULL THEN
i_result := 'Starting price range should be valid and cannot be empty';
RAISE V_MINPRICE; -- Raising exception if starting price is null
END IF;
--Checking if end price range is valid or not
IF c_maxprice IS NULL THEN
i_result := 'End price range should be valid and cannot be empty';
RAISE V_MAXPRICE; -- Raising exception if end price is null
END IF;
Your procedure requires three parameters so you have to pass in three parameters
DECLARE
l_result varchar2(100);
BEGIN
get_phone( 200, 500, l_result );
END;
/
should work. Of course, your procedure seems rather pointless. And if the goal is simply to return a result, you really ought to be using a function rather than a procedure with an out parameter.
get_phone expects 3 arguments, c_minprice, c_maxprice and i_result. You are only passing it one number. Pass it the rest of the arguments.
Related
I have function in oracle apex that returns true or false. When i use sqlcommand function of oracle apex I'm not able to execute the function
function authenticateUser(p_username in varchar2 ,p_password in varchar2 )
return boolean
is
p_user Users.USERNAME%type;
begin
select USERNAME into p_user from Users where upper(USERNAME)=upper(p_username) and upper(PASSWORD) = upper(p_password);
return true;
exception
when NO_DATA_FOUND then
return false;
end authenticateUser;
When i run
begin
PKG_AUTHORIZATION.authenticateUser(:p_username,:p_password);
end;
It display error as
ORA-06550: line 3, column 1:
PLS-00221: 'AUTHENTICATEUSER' is not a procedure or is undefined
ORA-06550: line 3, column 1:
PL/SQL: Statement ignored
ORA-06512: at "SYS.DBMS_SQL", line 1721
1. begin
2. PKG_AUTHORIZATION.authenticateUser(:p_username,:p_password);
3. end;
and When I write
select PKG_AUTHORIZATION.authenticateUser(:p_username,:p_password) from dual;
It throws error as
ORA-00902: invalid datatype
I suppose that function exists within the package, right?
As it returns Boolean, you can't use it directly from SQL, but PL/SQL, such as:
declare
l_val varchar2(20);
begin
l_val := case when PKG_AUTHORIZATION.authenticateUser(:p_username,:p_password) then 'true'
else 'false'
end;
end;
But, you don't have to worry about it. As you tagged the question with the Oracle Apex tag, I presume you use this function for your own authentication (instead of built-in one). If that's so, you just have to name the function which is supposed to do the job and put its name into the "Authentication function name" item.
I'm trying to execute a below SP and it throws be the below error:
CREATE OR REPLACE PROCEDURE denodo.CLEAR_INDEX
( INDEX_NAME1 IN VARCHAR2,
INDEX_NAME2 IN VARCHAR2,
IT_WORKED OUT BOOLEAN ) as
BEGIN
IT_WORKED := FALSE;
EXECUTE IMMEDIATE 'drop index ' || INDEX_NAME1;
EXECUTE IMMEDIATE 'drop index ' || INDEX_NAME2;
IT_WORKED := TRUE;
EXCEPTION
WHEN OTHERS THEN
IT_WORKED := FALSE;
END CLEAR_INDEX;
CLEAR_INDEX#0 [JDBC ROUTE] [ERROR] Received exception with message 'ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CLEAR_INDEX'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
What is going on here? appreciate your help.
This error you generally face when you deal with BOOLEAN datatype as OUT parameter and you try to print it or do any operation with any other inbuilt Oracle packages. You cannot directly use BOOLEAN datatype in dbms_output.put_line or any other DBMS package. For instance,if you want to print the OUT parameter you need to use sys.diutil.bool_to_int.
See below example which demonstrate the error you faced when you try to execute as below:
DECLARE
inx VARCHAR2(100):='ABC';
var BOOLEAN;
BEGIN
CLEAR_INDEX(INDEX_NAME1=>inx ,IT_WORKED =>var);
dbms_output.put_line(var);
END;
You face the issue:
ORA-06550: line 6, column 3:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 6, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action
To overcome such issue you must execute as below:
DECLARE
inx VARCHAR2(100):='ABC';
var BOOLEAN;
var1 varchar2(10);
BEGIN
CLEAR_INDEX(INDEX_NAME1=>inx ,IT_WORKED =>var);
var1:=CASE WHEN (sys.diutil.bool_to_int(var)) = 1 THEN 'TRUE'
WHEN (sys.diutil.bool_to_int(var)) = 0 THEN 'FALSE'
END;
dbms_output.put_line(var1);
END;
Output:
anonymous block completed
Mine is a similar case, however, a different call to a function, which has return type as Boolean and the input to the function is varchar2.
So, this is what I am doing:
Declare
v_ret1 varchar2(1000);
v_ret BOOLEAN;
Begin
v_ret := CASE WHEN SEI_PROCESS_MF_MNL_INVC_PKG.f_process_mf_mnl_invc(v_ret1) = 1 THEN 'TRUE'
WHEN SEI_PROCESS_MF_MNL_INVC_PKG.f_process_mf_mnl_invc(v_ret1) = 0 THEN 'FALSE'
END;
dbms_output.put_line(v_ret);
end;
I just wanted to see output of v_ret so that I can use that for further decision making. If v_ret is of type Boolean, the output should be either "TRUE" or "FALSE".
I am trying to find duplicated values in a ttXs:
DECLARE
type invmXXs is table of inv_table.mobileId%type index by binary_integer;
ttXs invmXXs;
answer BOOLEAN;
BEGIN
-- out_exported_list is ref cursor
-- (...)
OPEN out_exported_list FOR
/* (....) */
FETCH out_exported_list
BULK COLLECT INTO ttXs;
answer := ttXs IS NOT A SET; -- ORA-06550
-- ...
END;
But I am getting ORA-06550 and I dont know why. How can I fix it?
Error at line 1 ORA-06550: line 46, column 14: PLS-00306: wrong number
or types of arguments in call to 'MULTISET_UNION_DISTINCT' ORA-06550:
line 46, column 1: PL/SQL: Statement ignored
Below is a very simplified example in whcih you can try to handle/Find out Duplicate with nested tables. You are trying to achiev this by using Associative Array which doesnt support SET operations. Hope this helps.
set serveroutput on;
DECLARE
TYPE lv_var
IS
TABLE OF VARCHAR2(100);
v_tab lv_var;
v1_tab lv_var;
BEGIN
v_tab :=lv_var('a','a','b','c','d','d','e');
v1_tab:=SET(v_tab);
v1_tab:=SET(v_tab MULTISET
EXCEPT v1_tab);
FOR i IN v1_tab.FIRST..v1_tab.LAST
LOOP
dbms_output.put_line(v1_tab(i));
END LOOP;
END;
I wrote the following procedure which was meant to be anonymous and remove all the vowels from a string, but when I call it I get an error: I've followed the advice given in a similar post, but it didn't help:Oracle PLS-00363: expression '' cannot be used as an assignment target
SQL> CREATE OR REPLACE PROCEDURE disemvowel (string IN OUT NVARCHAR2)
2 IS
3 BEGIN
4 DBMS_OUTPUT.PUT_LINE(translate(string,'euioa',''));
5 END disemvowel;
6 /
Procedure created.
So good so far, but now I call it:
SQL> BEGIN
2 disemvowel('hahahahaha');
3 END;
4 /
The Error message says:
disemvowel('hahahahaha');
*
ERROR at line 2:
ORA-06550: line 2, column 12:
PLS-00363: expression 'hahahahaha' cannot be used as an assignment target
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
Your procedure has IN OUT parameter. So while calling the procedure you should supply a variable to it, so that it can hold the value that the procedure gives back. You cannot supply a value directly, as it cannot be modified by the procedure.
DECLARE
param NVARCHAR2 (20) := 'hahahahaha';
BEGIN
disemvowel (param);
END;
/
Generate new VARCHAR2 type variable to assign your IN (input) string.
PROCEDURE sp_name(
ps_list IN VARCHAR2,
...
write here other IN's and OUT's
...
)
AS
ps_list_copy VARCHAR2 (32000);
BEGIN
ps_list_copy := ps_list;
...
do your works with ps_list_copy
...
...
EXCEPTION WHEN OTHERS THEN
....
END sp_name;
Create PLSQL procedure which takes a customer id as a parameter and shows
his/her booking. For each booking show room No, hotel, start date and duration
create or replace procedure emp_project(CustID NUMBER)
is
cursor ecur
is
select r.RoomNo, r.HotelName, StartDate, Duration
from Room r, Booking b
where r.RoomNo=b.RoomNo
and r.RoomNo = b.CustID;
begin
for erec in ecur loop
dbms_output.put_line(erec. RoomNo ||' '||erec. HotelName ||' '|| erec. Duration);
end loop;
end;
/
Can someone please explain What's wrong with my parameter?
I get this error when I run it:
SQL> exec emp_project
BEGIN emp_project; END;
*ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'EMP_PROJECT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Your procedure requires a parameter (nothing apparently wrong with that), but your call to it (exec emp_project... etc.) doesn't seem to provide one.
Try this:
exec emp_project(1); // or any appropriate value instead of 1