SQL Procedure Errors - oracle

i am learning mysql and have moved onto procedures. I have created a procedure and i am trying to run it. But when I run the procedure i am faced with lots of errors, the error point to lines that have no errors that I can see, can anyone help me out?
This is the procedure I have created
create or replace PROCEDURE AD_AGENCY_INFO(
v_ad_id IN ad_agency.AGENCY_ID%TYPE,
v_cert IN ad_agency.NO_OF_AD_RUNS%TYPE,
v_price IN ad_agency.CREDIT_WORTHY%TYPE,
v_agency_id IN ad_agency.AGENCY_ID%TYPE
) AS
BEGIN
UPDATE AD SET AD_ID = v_ad_id, CERTIFICTAION = v_cert, PRICE = v_price where agency_id = v_agency_id;
INSERT INTO AD_SLOT (AD_ID) VALUES (v_ad_id);
EXCEPTION
WHEN NO_DATA_FOUND THEN
rollback;
END AD_AGENCY_INFO;
This is how I am calling the procedure
DECLARE
V_AGENCY_ID NUMBER:=&Enter_Agency_ID;
V_NO_OF_RUNS NUMBER:=&Enter_No_of_Runs;
V_CREDIT_WORTHY CHAR(3):=&Enter_Credit_Worthy;
V_AVAILABLE_SLOTS NUMBER:=&Enter_Available_Slots;
V_STATUS CHAR(1):=&Enter_Status;
BEGIN
V_AGENCY_ID := NULL;
V_NO_OF_RUNS := NULL;
V_CREDIT_WORTHY := NULL;
V_AVAILABLE_SLOTS := NULL;
V_STATUS := NULL;
AD_AGENCY_INFO(
V_AGENCY_ID => V_AGENCY_ID,
V_NO_OF_RUNS => V_NO_OF_RUNS,
V_CREDIT_WORTHY => V_CREDIT_WORTHY,
V_AVAILABLE_SLOTS => V_AVAILABLE_SLOTS,
V_STATUS => V_STATUS
);
END;
And this is the error log I get after running the procedure
Error report -
ORA-06550: line 4, column 28:
PLS-00201: identifier 'N' must be declared
ORA-06550: line 4, column 19:
PL/SQL: Item ignored
ORA-06550: line 6, column 21:
PLS-00201: identifier 'Y' must be declared
ORA-06550: line 6, column 12:
PL/SQL: Item ignored
ORA-06550: line 10, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
ORA-06550: line 12, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 12, column 3:
PL/SQL: Statement ignored
ORA-06550: line 17, column 24:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 14, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

In the script that you're using to call the procedure, you're using substitution variables. They are replaced by their value before the script is interpreted. This means that a line like V_CREDIT_WORTHY CHAR(3):=&Enter_Credit_Worthy; with the value "no" will be translated into V_CREDIT_WORTHY CHAR(3):=no; You'll notice that "no" is unquoted there. In order to use substitution variables to pass a string to a PL/SQL script, you need to enclose the bind variable in quotes: V_CREDIT_WORTHY CHAR(3):='&Enter_Credit_Worthy';.
An alternative would be to use bind variables. They are interpreted as a part of the script and can therefore be treated as normal variable. To do this, you would simply need to replace the ampersands with colons. The line I referenced above would become V_CREDIT_WORTHY CHAR(3):=:Enter_Credit_Worthy;.

Related

I don't understand what is the problem in my store procedure

Create or replace PROCEDURE SSp_EmpHoursInfo
(p_EHrsInfo OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_EHrsInfo FOR
Select
a.personid, a.first_name, a.last_name,c.hoursworked,d.carecentername, c.break
from person a
join employee b on a.personid = b.empersonid
join employee_assigned_care_center c on b.empersonid = c.empersonid
join care_center d on c.empersonid = d.carecenterid
where hoursworked> 10;
END SSp_EmpHoursInfo;
Everytime I am trying to call the store procedure it is giving me this error msg:
Error starting at line : 225 in command -
BEGIN SSp_EmpHoursInfo (hoursworked> 10); END;
Error report -
ORA-06550: line 1, column 3:
PLS-00201: identifier 'HOURSWORKED' must be declared
ORA-06550: line 1, column 52:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
The problem is very obvious.
BEGIN SSp_EmpHoursInfo (hoursworked> 10); END; is not the proper way of calling it.
The procedure parameter must be the sys_refcursor.
You must use:
DECLARE
OUTPUT_CUR SYS_REFCURSOR;
BEGIN
SSp_EmpHoursInfo (OUTPUT_CUR );
-- USE CURSOR ACCORDINGLY
END;
/

error PLS-00201: identifier kurtwb must be declared [duplicate]

This question already has an answer here:
PLS-00201: identifier 'USER INPUT' must be declared
(1 answer)
Closed 10 months ago.
I am executing one PL/SQL program but i am getting the error PLS-00201: identifier 'KURTWB' must be declared
DECLARE
create_user dba_users%ROWTYPE;
model_id varchar2(20);
user_name varchar2(20);
BEGIN
model_id:=&model_id;
user_name:=&user_name;
Select * INTO create_user from dba_users where username=model_id;
EXECUTE IMMEDIATE 'create user user_name identified by password
user_name default tablespace create_user.default_tablespace
temporary tablespace create_user.temporary_tablespace profile
create_user.profile;';
END;
/
Below is the value entered by me
Enter value for model_id: kurtwb
old 6: model_id:=&model_id;
new 6: model_id:=kurtwb;
Enter value for user_name: rohit
old 7: user_name:=&user_name;
new 7: user_name:=rohit;
Below is the error that i am getting
ERROR at line 6:
ORA-06550: line 6, column 11:
PLS-00201: identifier 'KURTWB' must be declared
ORA-06550: line 6, column 1:
PL/SQL: Statement ignored
ORA-06550: line 7, column 12:
PLS-00201: identifier 'ROHIT' must be declared
ORA-06550: line 7, column 1:
PL/SQL: Statement ignored
You have entered kurtwbas a value of the substitution variable named &model_id.
SQLPLus (or Oracle-SQL-Developer`) substitutes this variable in this line:
BEGIN
model_id:=&model_id;
....
....
with the entered value kurtwb. After the substitution the code looks like this:
BEGIN
model_id:=kurtwb;
....
....
since kurtwb is not defined anywhere, you get PLS-00201: identifier 'KURTWB' must be declared error.
I guess you want to store kurtwb as a string in model_id variable, in this case you must use apostropher aroud the substitution variables:
BEGIN
model_id:='&model_id';
....
....

Why anonymous oracle stored procedure is working but named not

I'm trying to create a simple SP in the Oracle 11.2.0.4.0 which will execute a simple update statement like
update t set col1 = 1 where col2 = 2;
When i'm doing it in the anonymous stored procedure it works fine
begin
update t set col1 = 1 where col2 = 2;
end;
But if I'm trying to create a procedure
create or replace procedure p as
begin
update t set col1 = 1 where col2 = 2;
end;
And trying to run it, i'm gets a lot of errors:
ORA-06550: line 9, column 13:
PLS-00201: identifier 'SYS.DBMS_SQL' must be declared
ORA-06550: line 9, column 13:
PL/SQL: Item ignored
ORA-06550: line 16, column 13:
PLS-00201: identifier 'SYS.DBMS_LOB' must be declared
ORA-06550: line 16, column 13:
PL/SQL: Item ignored
Can any one explain how it happened, why sp is trying to get objects from SYS schema? Why it works in case of anonymous sp and not working in case of named SP?

trigger compiling error in sqldeveloper with oracle11g

I have been studying triggers from
[ http://www.tutorialspoint.com/plsql/plsql_triggers.htm][1]
with sqldeveloper and I connected Oracle 11g database. I created customers table successfully. But when I tried to create trigger as :
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
I get these errors:
Error starting at line : 1 in command -
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number
Error report -
SQL Command: trıgger DISPLAY_SALARY_CHANGES
Failed: Warning: yürütme uyarı ile tamamlandı
Error starting at line : 7 in command -
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
Error report -
ORA-06550: line 2, column 5:
PLS-00201: identifier 'SAL_DIFF' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
ORA-06550: line 3, column 60:
PLS-00487: Invalid reference to variable 'SQLDEVBIND1Z_2'
ORA-06550: line 3, column 5:
PL/SQL: Statement ignored
ORA-06550: line 4, column 60:
PLS-00487: Invalid reference to variable 'SQLDEVBIND1Z_1'
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
ORA-06550: line 5, column 51:
PLS-00201: identifier 'SAL_DIFF' must be declared
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What is wrong with this create trigger block?
It seems to be the same "Securing Literals" feature as described here
http://krisrice.io/2015-09-11-sqlcl-more-secure-now-with-rest/

got pls-00201 when I call a package via public synonym in Oracle

I created a package named sf_timer in sys, then I created a public synonym on this:
create or replace public synonym sf_timer for sys.sf_timer;
select * from all_synonyms where synonym_name = 'SF_TIMER';
Then I call this package from another user:
set serveroutput on
declare
i integer;
j integer;
begin
sf_timer.start_timer;
for i in 1..100000
loop
j := j +1;
end loop;
sf_timer.show_elapsed_time('Test 1');
end;
/
Unfortunately I got error below:
Error report:
ORA-06550: line 5, column 3:
PLS-00201: identifier 'SF_TIMER' must be declared
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored
ORA-06550: line 10, column 3:
PLS-00201: identifier 'SF_TIMER' must be declared
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
I can see this public synonym from all_synonyms but I don't know why I cannot call the package in my schema.
Thanks in advance.
Have you granted permissions?
When running as SYS, do this...
GRANT EXECUTE ON SYS.SF_TIMER TO <user-you're-using>;
As a further note it's generally regarded as bad practise to create objects in the SYS schema :-)

Resources