I have a procedure that looks like this:
PROCEDURE myprocedure (
i_area IN somenumber%TYPE,
io_areadata IN OUT areacursor
);
And I wonder if there is any simple way to call procedure? I have data for the first argument but for the second I do not know what enter. Is there any way I could enter an empty cursor or something similar?
This is what I've done so far:
BEGIN
package.myprocedure (
12345
);
END;
And that gives me the following error:
Error report:
ORA-06550: row 2, column 1:
PLS-00306: wrong number or types of arguments in call to 'MYPROCEDURE'
ORA-06550: row 2, column 1:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Thank you in advance and sorry for my (maybe) poor explanation. I have little experience in PL/SQL.
You have to supply that parameter. You could do this:
DECLARE
dummy package.areacursor;
BEGIN
package.myprocedure (
12345, dummy
);
END;
By this way you can call a stored procedure by passing particular value to a particular parameter.
Try this.
Begin
package.myprocedure(i_area => '12345);
end;
Related
I'm a beginner to sql and I'm having troubling calling a stored procedure. I have put down the procedure, call, and error. I have been researching for hours trying to figure out why I'm getting this error. I am a database administrator. Oracle Database 11g Express Edition.
Thanks for any help.
Procedure
CREATE OR REPLACE PROCEDURE DISP_GUIDE_NAM (I_GUIDE_NUM IN GUIDE.GUIDE_NUM%TYPE) AS
I_LAST_NAME GUIDE.LAST_NAME%TYPE;
I_FIRST_NAME GUIDE.FIRST_NAME%TYPE;
SET SERVEROUTPUT ON;
BEGIN
SELECT LAST_NAME, FIRST_NAME
INTO I_LAST_NAME, I_FIRST_NAME
FROM GUIDE
WHERE GUIDE_NUM=I_GUIDE_NUM;
DBMS_OUTPUT.PUT_LINE(RTRIM(I_FIRST_NAME)||' '||RTRIM(I_LAST_NAME));
END;
/
Call
begin
disp_guide_nam('AM01');
end;
/
Error:
ORA-06550: line 2, column 1:
PLS-00201: identifier 'DISP_GUIDE_NAM' must be declared
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
1. begin
2. disp_guide_nam('AM01');
3. end;
4. /
it should give me guide number, first name last name.
Actually I want to get usernames from table using Stored Procedure
CREATE OR REPLACE PROCEDURE GetRecord
(
p_ID IN integer ,
p_user OUT VARCHAR2
)
AS
BEGIN
SELECT
USERNAMES
INTO
p_user
FROM tblUsers
WHERE ID = p_ID ;
END GetRecord;
BEGIN
DECLARE A VARCHAR2
EXECUTE GetRecord(21,A);
END
When I run the above procedure I got following errors
Error starting at line : 17 in command -
BEGIN
DECLARE A VARCHAR2
EXECUTE GetRecord(21,A);
END
Error report -
ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "EXECUTE" when expecting one of the following:
:= . ( # % ; not null range default character
The symbol ";" was substituted for "EXECUTE" to continue.
ORA-06550: line 4, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Actually I want to get usernames from table using Stored Procedure
The code that you are using to execute your procedure appears to be incorrect. It sounds like you want
DECLARE
l_usernames tblUsers.usernames%type;
BEGIN
GetRecord( 21, l_usernames );
END;
In general, I'd strongly object to your naming convention. It makes no sense to use a plural usernames as a column name. A procedure named GetRecord tells you nothing about what it does-- GetUsername would be much more meaningful. Your anonymous block also appears to be declaring a local variable a that stores the returned username which also makes no sense from the standpoint of using meaningful identifiers.
I'd also suggest that a procedure is the wrong approach here. If your goal is to return a single value, use a function. Functions return things, procedures do not. A function can potentially be used in a SQL statement, a procedure cannot be.
I'm running Oracle SQL developer and I've got the following Stored Procedure. I'm quite new to this but really not sure why this isn't working:
CREATE OR REPLACE PROCEDURE CHECKDUPLICATE(
username1 IN USERS.USERNAME%TYPE,
o_username OUT USERS.USERNAME%TYPE
)
IS
BEGIN
SELECT USERNAME
INTO o_username
FROM USERS WHERE username1 = o_username;
END;
When I try to call it:
DECLARE
o_username USERS.USERNAME%TYPE;
BEGIN
CHECKDUPLICATE('Jacklin', o_username);
DBMS_OUTPUT.PUT_LINE('username : ' || o_username);
END;
I get the error message:
Error starting at line 1 in command:
DECLARE
o_username USERS.USERNAME%TYPE;
BEGIN
CHECKDUPLICATE(Jacklin, o_username);
DBMS_OUTPUT.PUT_LINE('username : ' || o_username);
END;
Error report:
ORA-06550: line 5, column 19:
PLS-00201: identifier 'JACKLIN' must be declared
ORA-06550: line 5, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What does it mean by "Identifier 'Jacklin' must be declared? (Table is called USERS, and column name is called USERNAME). Any help would be appreciated.
EDIT** I put Jacklin in quotes, and I get this message now:
Error report:
ORA-01403: no data found
ORA-06512: at "L13JAV04.CHECKDUPLICATE", line 9
ORA-06512: at line 6
01403. 00000 - "no data found"
*Cause:
*Action:
Even though Jacklin does it exist in the database!
Once you quote 'Jacklin' so that it's treated as a string literal rather than an identifier, your SQL statement doesn't look right.
SELECT USERNAME
INTO o_username
FROM USERS
WHERE username1 = o_username;
My wager is that you want to use the input parameter in your WHERE clause, not the output parameter.
SELECT USERNAME
INTO o_username
FROM USERS
WHERE username1 = username;
It doesn't make sense to check the value of an output parameter when you haven't done anything to initialize it.
But your code still doesn't seem to make sense. A SELECT INTO will throw an error if anything other than 1 row is returned. If your query returns 0 rows, you'll get a NO_DATA_FOUND exception. If your query returns more than 1 row, you'll get a TOO_MANY_ROWS exception. Your procedure is named CheckDuplicate so I'm guessing that it's purpose is to check whether a particular username already exists in the table rather than trying to insert it and catching the unique constraint violation error. If that is the intention of your code
You probably want it to be a function
You probably don't want to return the username
You probably want to return an indicator of whether the username already exists
My guess, therefore, is that you would want something like
create or replace function isAvailable( p_username IN USERS.USERNAME%TYPE )
return Boolean
is
l_username USERS.USERNAME%TYPE;
begin
select username
into l_username
from users
where username = p_username;
return false;
exception
when no_data_found
then
return true;
end;
You need to put Jacklin within quotes for it to be treateed as a string. Otherwise the parser thinks it's a field name.
There would have been no user by name of "Jacklin" thats why its giving you the error. Please add an exception at the end
WHEN NO_DATA_FOUND
THEN
......
I have a table from where I want get next lowest priority DVDid, give me that as output and delete it from table. I'm doing this by creating a Package...code gets compiled but when I execute it give me error. Any suggestion?
table:
RENTALQUEUE (MEMBERID, DVDID, DATEADDEDINQUEUE, PRIORITY)
Here is the package:
create or replace
PACKAGE pk_GET_TITLEID AS
procedure sp_GET_TITLEID(memberid_arg IN NUMBER,
titleid_arg out number) ;
end pk_GET_TITLEID;
create or replace
package body pk_GET_TITLEID as
procedure sp_GET_TITLEID
(memberid_arg IN NUMBER,
titleid_arg out number)
IS
v_priority number;
begin
SELECT MIN(PRIORITY)into v_priority
FROM RENTALQUEUE
WHERE memberid = memberid_arg;
DBMS_OUTPUT.PUT_LINE (titleid_arg);
DELETE FROM RENTALQUEUE
WHERE MEMBERID=memberid_arg AND dvdid=titleid_arg;
END sp_GET_TITLEID;
END PK_GET_TITLEID;
Here is how I call it:
execute pk_get_titleid.sp_get_titleid('1');
Here is the error:
Error:
Error starting at line 403 in command:
execute pk_get_titleid.sp_get_titleid('1')
Error report:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_GET_TITLEID'
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.
The error is:
PLS-00306: wrong number or types of arguments in call to 'SP_GET_TITLEID'
How many parameters does your procedure have in its signature?
procedure sp_GET_TITLEID
(memberid_arg IN NUMBER
, titleid_arg out number)
Two. How many parameters are you passing?
execute pk_get_titleid.sp_get_titleid('1')
One.
An out parameter is still a parameter. You need to include it in the call. Specifically you need a variable in the calling environment which can receive the answer from the called procedure. The fact that your code doesn't actually populate the titleid_arg parameter doesn't affect this.
The non-population of the titleid_arg parameter just highlights the confusion in your code. Perhaps it should be an IN parameter? Perhaps you need to select it from another table? What is the point of v_priority?
This is my first run through with PL SQL so I might be making some sort of silly error.
I am trying to write a procedure in Oracle Express Edition 11g. I am running into an error that has to do with my WITH clause in the procedure body.
Whenever I try and run it I see two errors.
Error report:
ORA-06550: line 14, column 50:
PL/SQL: ORA-00918: column ambiguously defined
ORA-06550: line 12, column 7:
PL/SQL: SQL Statement ignored
ORA-06550: line 29, column 3:
PLS-00306: wrong number or types of arguments in call to 'FIND_HIGH_AVG'
ORA-06550: line 29, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Code for the procedure is found below.
DECLARE
myTerm courses.term%type;
myLine courses.lineno%type;
procedure find_high_avg (term IN courses.term%type,
line IN courses.lineno%type,
s_fname OUT students.fname%type,
s_lname OUT students.lname%type,
s_sid OUT students.side%type,
s_avg OUT number) is
begin
WITH grades as (select * from components co --line 12 here
join scores sc on co.term = sc.term and co.lineno = sc.lineno and CO.COMPNAME = SC.COMPNAME
where sc.lineno = line and sc.term = term) --line 14 here
select *
into s_fname, s_lname, s_sid, s_avg
from (
select s.fname, s.lname, s.sid, round(sum(points/maxpoints * weight),0) as AV
from grades, students
join students s on grades.sid = s.sid
group by s.sid, s.fname, s.lname
order by AV)
where rownum = 1;
end;
BEGIN
myTerm:='F12';
myLine:='1031';
find_high_avg(myTerm, myLine); --line 29 here
END;
The error at line 10 occurs because parameters to stored procedures do not take a length. The procedure declaration should be something like
procedure find_high_avg (term IN courses.term%type,
line IN courses.lineno%type,
s_fname OUT students.fname%type,
s_lname OUT students.lname%type,
s_sid OUT students.side%type,
average OUT number)
is
The error at line 14 is likely because the parameters to your procedure have the same name as columns in your table. In a SQL statement's scope resolution rules, column names take precedence over local PL/SQL variables. So when you code something like
sc.term = term
Oracle tries to resolve the unqualified TERM using a column in one of the tables. If both tables have a column named TERM, that generates an ambiguous column reference-- Oracle doesn't know which of the two tables to use. Of course, in reality, you don't want it to use the column from either table, you want it to use the parameter. The most common approach to this problem is to add a prefix to your parameter names to ensure that they do not collide with the column names. Something like
procedure find_high_avg (p_term IN courses.term%type,
p_line IN courses.lineno%type,
s_fname OUT students.fname%type,
s_lname OUT students.lname%type,
s_sid OUT students.side%type,
p_average OUT number)
is
The error on line 29 occurs because the procedure takes 6 parameters-- 2 IN and 4 OUT. In order to call it, therefore, you would need to use 6 parameters. Something like
DECLARE
myTerm courses.term%type;
myLine courses.lineno%type;
l_fname students.fname%type;
l_lname students.lname%type;
l_sid students.side%type;
l_avg number;
BEGIN
myTerm:='F12';
myLine:='1031';
find_high_avg(myTerm, myLine,l_fname,l_lname, l_sid, l_avg);
END;
I think it should be end find_high_avg; instead of end; after the select statement.