error PLS-00103 while running a procedure - oracle

I am a newbie in plsql and trying to implement a code that uses procedure to perform some task.I am using oracle 10g.I have already made a package named stu_pack and am trying to make package body but in vain.Please help.
I want to make a procedure that gives student details for given course name.
the code is as below.
the error message is:
ERROR at line 14: PLS-00103: Encountered the symbol "PROCEDURE" when
expecting one of the following: ; delete exists prior
The symbol ";" was substituted for "PROCEDURE" to continue.
create or replace package body stu_pack as
procedure proc1(cname IN number) as
l_cname number(2);
CREATE OR REPLACE PACKAGE BODY stu_pack AS
PROCEDURE proc1 (
cname IN NUMBER
) AS
l_cname NUMBER(2);
cur1 student%rowtype;
CURSOR c1 IS SELECT
s.*
FROM
student s,
course c,
learn l
WHERE
c.cname = l_cname
AND c.cid = l.cid
AND s.sid = l.sid;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO cur1;
EXIT WHEN c%notfound;
dbms_output.put_line('student roll number:'
|| cur1.sid
|| ' student
name:'
|| cur1.sname
|| ' phone number:'
|| cur1.phone);
END LOOP;
CLOSE c1;
END procedure proc1;
END stu_pack;
/

You need to change the line end procedure proc1;
It should be simply
end;
oR
end proc1;

Related

PLS-00103: Encountered the symbol "DBMS_OUTPUT" when expecting one of the following:

I got a pl/sql error when I try to run this package. How can I solve this?
CREATE OR REPLACE PACKAGE pkg_ref_value
IS
ref_value orders.total_order%TYPE;
PROCEDURE proc_display_firstname( cust_id IN customer.customer_id%TYPE);
PROCEDURE proc_ref_value(orderId IN orders.order_id%TYPE);
END pkg_ref_value;
PROCEDURE proc_display_firstname( cust_id IN customer.customer_id%TYPE)
IS
cust_last_name VARCHAR2(20);
CURSOR c1(cust_id customer.customer_id%TYPE ) IS
SELECT UPPER(CONCAT(CONCAT(cust_first_name,' '),cust_last_name)) FROM customer WHERE
customer_id=cust_id;
BEGIN
OPEN c1(cust_id);
LOOP
FETCH c1 INTO cust_last_name;
EXIT
WHEN c1%NOTFOUND
DBMS_OUTPUT.PUT_LINE(cust_last_name);// this is the place I got error
END LOOP;
CLOSE c1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND' );
END proc_display_firstname;
PROCEDURE proc_ref_value(orderId IN orders.order_id%TYPE)
IS
or_status orders.order_id%TYPE;
total orders.total_order%TYPE;
v_order_id orders.order_id%TYPE :=orders_id;
CURSOR c2 (orderId orders.order_id%TYPE) IS
SELECT
CASE
WHEN order_status='refunded' THEN total_order*0.25
WHEN order_status='completed' THEN total_order* 0
WHEN order_status='cancelled' THEN total_order*0
END
FROM orders;
BEGIN
v_cust_last_name :=proc_display_firstname(v_order_id);
SELECT order_id,order_status, total_order INTO v_order_id,or_status,total
FROM orders
WHERE order_id = v_order_id;
OPEN c2(orderId);
LOOP
FETCH c2 INTO ref_value;
EXIT WHEN c2%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(ref_value);
END LOOP;
CLOSE c2;
DBMS_OUTPUT.PUT_LINE('cust name:'||v_cust_last_name||' Order Id'||v_order_id||'Order Status'||or_status||'Refund Value'||ref_value);
END proc_ref_value;
END pkg_ref_value;'
There are a few problems here:
You have the statement to create the package spec (CREATE OR REPLACE PACKAGE) but you missed the statement required to create the package body (CREATE OR REPLACE PACKAGE BODY).
You're missing a semi-colon after EXIT WHEN c1%NOTFOUND.
In v_order_id orders.order_id%TYPE :=orders_id;, there is no variable named orders_id which is in scope. I suspect you meant orderId.
The updated package code is shown below:
CREATE OR REPLACE PACKAGE pkg_ref_value IS
ref_value orders.total_order%TYPE;
PROCEDURE proc_display_firstname( cust_id IN customer.customer_id%TYPE);
PROCEDURE proc_ref_value(orderId IN orders.order_id%TYPE);
END pkg_ref_value;
CREATE OR REPLACE PACKAGE BODY pkg_ref_value IS -- add
PROCEDURE proc_display_firstname( cust_id IN customer.customer_id%TYPE) IS
cust_last_name VARCHAR2(20);
CURSOR c1(cust_id customer.customer_id%TYPE ) IS
SELECT UPPER(CONCAT(CONCAT(cust_first_name,' '),cust_last_name))
FROM customer
WHERE customer_id=cust_id;
BEGIN
OPEN c1(cust_id);
LOOP
FETCH c1 INTO cust_last_name;
EXIT WHEN c1%NOTFOUND; -- add ;
DBMS_OUTPUT.PUT_LINE(cust_last_name); -- this is the place I got error
END LOOP;
CLOSE c1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND' );
END proc_display_firstname;
PROCEDURE proc_ref_value(orderId IN orders.order_id%TYPE) IS
or_status orders.order_id%TYPE;
total orders.total_order%TYPE;
v_order_id orders.order_id%TYPE := orderId; -- changed from := orders_id
CURSOR c2 (orderId orders.order_id%TYPE) IS
SELECT CASE
WHEN order_status='refunded' THEN total_order*0.25
WHEN order_status='completed' THEN total_order* 0
WHEN order_status='cancelled' THEN total_order*0
END
FROM orders;
BEGIN
v_cust_last_name := proc_display_firstname(v_order_id);
SELECT order_id,order_status, total_order
INTO v_order_id,or_status,total
FROM orders
WHERE order_id = v_order_id;
OPEN c2(orderId);
LOOP
FETCH c2 INTO ref_value;
EXIT WHEN c2%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(ref_value);
END LOOP;
CLOSE c2;
DBMS_OUTPUT.PUT_LINE('cust name:' || v_cust_last_name ||
' Order Id' || v_order_id ||
' Order Status' || or_status ||
' Refund Value' || ref_value);
END proc_ref_value;
END pkg_ref_value;

PLS-00103: Encountered the symbol "PROCEDURE" when expecting one of the following:

Im a learning plsql and im trying to create procedure and calling procedure inside another procedure and i can get desired output. But when i tried to create procedure inside another procedure instead of calling another procedure, im getting the below error
"23/1 PLS-00103: Encountered the symbol "PROCEDURE" when expecting one of the following: ( begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge The symbol "declare" was substituted for "PROCEDURE" to continue.
23/18 PLS-00103: Encountered the symbol "." when expecting one of the following: in out ... long double ref char time timestamp interval date binary national character nchar
Errors: check compiler log
"
CREATE OR REPLACE PROCEDURE pro (
empn NUMBER,
emp OUT emp5%rowtype
) IS
salar number;
BEGIN
SELECT
a.*
INTO emp
FROM
emp5 a
WHERE
a.empno = empn;
dbms_output.put_line('The hire date is'
|| ' '
|| emp.hiredate);
dbms_output.put_line('Name is'
|| ' '
|| emp.ename);
procedure p44(emp.hiredate in date,emp.ename varchar,sal out number) IS
salar NUMBER;
BEGIN
SELECT
e.sal
INTO salar
FROM
emp5 e
WHERE
e.hiredate = hire
AND e.ename = enamee;
dbms_output.put_line('salary of the employee'
|| ' '
|| enamee
|| 'is '
|| salar);
END p43;
/
If i give empno number as input to procedure pro, i need output with employees hiredate,employee's name and employee's salary like the below one
The hire date is 20-FEB-81
Name is ALLEN
salary of the employee ALLEN is 1600
A procedure is a single program unit with the structure of:
create or replace procedure p43 () is
...
begin
…
end;
/
Your code has two instances of PROCEDURE and that's what the compiler is complaining about.
If you want two separate procedures you need two separate CREATE statements:
create or replace procedure p43 () is
...
begin
…
end p43;
/
create or replace procedure p44 () is
...
begin
…
end p44;
/
But if what you want is P44 as a private procedure only accessible within the context of P43 you can do that, by defining the procedure in the declaration section after any variable declarations:
create or replace procedure p43 () is
…
procedure p44 () is
...
begin
…
end p44;
begin
…
p44(…);
end p43;
/
Also this is not how we declare parameters.
procedure p44(emp.hiredate in date,emp.ename varchar,sal out number) IS
Give them unique names, say by prefixing them with p_, and if you like use the table column datatype. Something like this:
procedure p44(p_hiredate in emp.hiredate%type
,p_ename in emp.ename%type
,p_sal out emp.sal%type) IS
Giving parameters a distinct name prevents scope confusion when using parameters in SQL statements:
You can not create procedure within procedure.
Procedure is a single object and must be created alone. You can call one procedure from another.
You can use package to create multiple procedures inside single package but in that case also, procedure must be created standalone.
-- procedure must be created standalone
Create or replace procedure p44
As
Begin
-- code
End p44;
/
Create or replace procedure pro
As
Begin
P44; -- call to existing procedure
-- code
End pro;
/
So your case will go like this:
procedure p44(hiredate in date,ename varchar,sal out number) IS
salar NUMBER;
BEGIN
SELECT
e.sal
INTO salar
FROM
emp5 e
WHERE
e.hiredate = hire
AND e.ename = ename;
dbms_output.put_line('salary of the employee'
|| ' '
|| ename
|| 'is '
|| salar);
END p44;
/
CREATE OR REPLACE PROCEDURE pro (
empn NUMBER,
emp OUT emp5%rowtype
) IS
salar number;
BEGIN
SELECT
a.*
INTO emp
FROM
emp5 a
WHERE
a.empno = empn;
dbms_output.put_line('The hire date is'
|| ' '
|| emp.hiredate);
dbms_output.put_line('Name is'
|| ' '
|| emp.ename);
P44(emp.hiredate, emp.ename, salr):
END pro;
/
Cheers!!

PLS-00103: Encountered the symbol ";" when expecting one of the following: case The symbol "case" was substituted for ";" to continue

I have a problem in my package body
Here is code:
CREATE OR REPLACE PACKAGE BODY emp_data IS
PROCEDURE open_emp_cur_var(cv_emp IN OUT rt_emp, p_your_choice IN NUMBER)
IS
BEGIN
CASE
when p_your_choice=1 then open cv_emp for SELECT * FROM employees;
else OPEN cv_emp for SELECT * FROM employees WHERE salary > 8000;
end;
end;
end open_emp_cur_var;
END emp_data;
It returns me it was compiled with errors.
This is two errors it returns me.
8/16 PLS-00103: Encountered the symbol ";" when expecting one of the following: case The symbol "case" was substituted for ";" to continue.
11/1 PLS-00103: Encountered the symbol "END"
Your first END needs to be END CASE; and you have an extra END:
CREATE OR REPLACE PACKAGE BODY emp_data IS
PROCEDURE open_emp_cur_var(cv_emp IN OUT rt_emp, p_your_choice IN NUMBER)
IS
BEGIN
CASE
WHEN p_your_choice=1 THEN
OPEN cv_emp for SELECT * FROM employees;
ELSE
OPEN cv_emp for SELECT * FROM employees WHERE salary > 8000;
END CASE;
END open_emp_cur_var;
END emp_data;
/
You may use IF..END IF if you are unfamiliar with CASE
Also, you are probably looking for a REFCURSOR OUT variable.
CREATE OR REPLACE PACKAGE emp_data IS
PROCEDURE open_emp_cur_var (
cv_emp OUT SYS_REFCURSOR , p_your_choice IN NUMBER
);
END;
/
CREATE OR REPLACE PACKAGE BODY emp_data IS
PROCEDURE open_emp_cur_var (
cv_emp OUT SYS_REFCURSOR, p_your_choice IN NUMBER
) IS
BEGIN
IF p_your_choice = 1 THEN
OPEN cv_emp FOR SELECT *
FROM employees;
ELSE OPEN cv_emp FOR SELECT *
FROM employees
WHERE salary > 8000;
END IF;
END;
END emp_data;
/

getting error while compiling the stored procedure

I am writing this below stored procedure but i am also getting the exception while compiling the procedure in oracle, below is the procedure
CREATE OR REPLACE PACKAGE BODY TEST_TABLE AS
PROCEDURE TEST_TABLE
--This procedure will delete partitions for the following tables:
--TEST_TABLE
BEGIN
FOR cc IN
(
SELECT partition_name, high_value
FROM user_tab_partitions
WHERE table_name = 'TEST_TABLE'
)
LOOP
EXECUTE IMMEDIATE 'BEGIN
IF sysdate >= ADD_MONTHS(' || cc.high_value || ', 3) THEN
EXECUTE IMMEDIATE
''ALTER TABLE TEST_TABLE DROP PARTITION ' || cc.partition_name || '
'';
END IF;
dbms_output.put_line('drop partition completed');
END;';
END LOOP;
exception
when others then
dbms_output.put_line(SQLERRM);
END;
END;
/
and the exception that I am getting it while compiling is Please advise how to overcome from this.
Error(7,1): PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: ( ; is with authid as cluster order using external deterministic parallel_enable pipelined result_cache The symbol ";" was substituted for "BEGIN" to continue.
Error(22,25): PLS-00103: Encountered the symbol "DROP" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem return returning <an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec between into using || bulk member submultiset
You need to make correct quotation as below( and one more is keyword just after PROCEDURE TEST_TABLE "thanks to Alex who make me awaken" ) :
CREATE OR REPLACE PACKAGE BODY PKG_TEST_TABLE IS
PROCEDURE TEST_TABLE IS
--This procedure will delete partitions for the following tables:
--TEST_TABLE
BEGIN
FOR cc IN
(
SELECT partition_name, high_value
FROM user_tab_partitions
WHERE table_name = 'TEST_TABLE'
)
LOOP
BEGIN
IF sysdate >= ADD_MONTHS(cc.high_value, 3) THEN
EXECUTE IMMEDIATE
'ALTER TABLE TEST_TABLE DROP PARTITION ' || cc.partition_name;
Dbms_Output.Put_Line('Dropping partition is completed.');
END IF;
END;
END LOOP;
EXCEPTION WHEN Others THEN Dbms_Output.Put_Line( SQLERRM );
END TEST_TABLE;
END PKG_TEST_TABLE;
/
As a little suggestion use a different name for package than procedure such as PKG_TEST_TABLE against confusion.
Edit : of course you need to create a specification part for a package before the body part of the package :
CREATE OR REPLACE PACKAGE PKG_TEST_TABLE IS
PROCEDURE TEST_TABLE;
END PKG_TEST_TABLE;
/
The first error message tells you something is missing before BEGIN, and even mentions the two possible options in the 'when expecting' list. You need to change it to:
PROCEDURE TEST_TABLE IS
-- ^^
Or you can use AS instead of IS if you prefer...
The second error is because you have a string literal embedded in your dynamic SQL and you haven't escaped the single quotes, though you have elsewhere:
...
dbms_output.put_line(''drop partition completed'');
-- ^ ^
END;';
You could use the alternative quoting mechanism instead.
I'm not sure why you're doing two levels of dynamic SQL; you can do the dbms_output() and evaluate cc.high_value statically, and decide whether to make the alter call, with only that part dynamic (as #BarbarosÖzhan has shown, so I wont repeat that!). Or do the high-value check within the cursor query.
I am still getting exception Error(1,14): PLS-00304: cannot compile body of 'TEST_TABLE' without its specification
If you want a package then you have to create its specification before you try to create its body:
CREATE OR REPLACE PACKAGE TEST_TABLE AS
PROCEDURE TEST_TABLE;
END TEST_TABLE;
/
CREATE OR REPLACE PACKAGE BODY TEST_TABLE AS
PROCEDURE TEST_TABLE IS
BEGIN
FOR cc IN
...
LOOP
...
END LOOP;
END TEST_TABLE; -- end of procedure
END TEST_TABLE; -- end of package
/
Having the package name the same as a procedure within it is a bit odd and confusing.
But maybe you didn't actually want a package at all, and were trying to create a standalone procedure, in which case just remove the package-body part:
CREATE OR REPLACE PROCEDURE TEST_TABLE AS
BEGIN
FOR cc IN
...
LOOP
...
END LOOP;
END TEST_TABLE; -- end of procedure
/
Read more.
I would strongly suggest you get rid of the exception handler, and I've left that out of those outlines - you should let any exception flow back to the caller. You don't know that whoever calls this will even have output enabled, so might well not even see the message you're printing instead. Only ever catch exceptions you can handle and need to handle at that point.

PLS-00103; is with authid as cluster compress order using compiled wrapped external deterministic parallel_enable pipel

While writing the below pl/sql procedure,
CREATE OR REPLACE PROCEDURE RTSPGMR."COMPARE"
DECLARE CURSOR comp IS
select EFF_DT,LOC_EFF_DT_FK from dcp d,loc l where D.LOC_CD_FK=L.LOC_CD;
BEGIN
for c1 in comp LOOP
if EFF_DT=LOC_EFF_DT_FK THEN
dbms_output.put_line('dates are equal');
Else
dbms_output.put_line('dates are not equal');
end if;
END LOOP;
COMMIT;
END;
I am getting the following error.
[Error] PLS-00103 (5: 1): PLS-00103: Encountered the symbol "DECLARE"
when expecting one of the following: ( ; is with authid as cluster
compress order using compiled wrapped external deterministic
parallel_enable pipel
Assuming rest of your code is fine, the syntax for procedure is incorrect. You don't need a declare and also you are missing as or is after procedure name. Try this.
CREATE OR REPLACE PROCEDURE RTSPGMR.COMPARE is
CURSOR comp IS
select EFF_DT,LOC_EFF_DT_FK from dcp d,loc l where D.LOC_CD_FK=L.LOC_CD;
BEGIN
for c1 in comp LOOP
if EFF_DT=LOC_EFF_DT_FK THEN
dbms_output.put_line('dates are equal');
else
dbms_output.put_line('dates are not equal');
end if;
END LOOP;
COMMIT;
END;

Resources