I have been getting a rather strange error for a long time in SQL developer.. I have stripped my package to the most basic and ran a variable declaration.. and even that is throwing an error.. this is what I am executing:
create or replace package body cdbmeta.pkg_metadata_check
is
procedure p_metadata_check(unit_id_start in number, unit_id_end in number)
is
begin
start_date NUMBER(10);
dbms_output.put_line('..');
end;
end;
and my error message states:
PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following: := . ( # % ; The symbol ":=" was substituted for "NUMBER" to continue.
Totally clueless.. anyone had this before?
You have to put definition of variables after the "is" and before "begin" as follows:
create or replace package body cdbmeta.pkg_metadata_check
is
procedure p_metadata_check(unit_id_start in number, unit_id_end in number)
is
start_date NUMBER(10);
begin
dbms_output.put_line('..');
end;
end;
/
The block in procedure definition after is and before begin is the same as You would use with anonymous block like this:
declare
start_date NUMBER(10);
begin
dbms_output.put_line('..');
end;
/
Related
I just currently learning about Oracle PL/SQL. I wanna create store procedure with variable and then call it with another script. Is it possible?
I tried use simple script without variable and it works:
CREATE OR REPLACE PROCEDURE testmyproc AS
BEGIN
INSERT INTO tes_table(dt)
VALUES (sysdate);
commit;
END testmyproc;
Then I call it with another script abc.sql
begin
testmyproc;
end;
It works successfully.
But, unfortunately if I use DECLARE (variable) at my PROCEDURE, it show error when I execute (but it success in create procedure).
Here's my PROCEDURE (no error):
CREATE OR REPLACE PROCEDURE sp_testmyproc AS
DECLARE
job_name varchar(100);
status_key number;
status_desc varchar(100);
notes varchar(250);
BEGIN
status_key := 1;
status_desc := 'SUCCESS';
notes := 'Process Completed';
INSERT INTO automation_log(job_name, dt, status_key, status_desc, notes)
VALUES (job_name, sysdate, status_key, status_desc, notes);
commit;
END sp_testmyproc;
Here's my execure script abc.sql (show error when i execute it)
-without DECLARE
begin
sp_testmyproc;
end;
-I tried to execute it with DECLARE
DECLARE
job_name varchar(100);
status_key number;
status_desc varchar(100);
notes varchar(250);
begin
status_key := 1;
status_desc := 'SUCCESS';
notes := 'Process Completed';
sp_testmyproc;
end;
It show error like this:
> ORA-06550: line 8, column 11:
> PLS-00905: SP_TESTMYPROC is invalid
> ORA-06550: line 8, column 3:
> PL/SQL: Statement ignored
Can I call Procedure for another script? Is It best practice?
I just think PROCEDURE can be used for many cases (something like function in programming).
Thank you!
You need to learn the syntax of the procedure.
In Procedure, You should not use the keyword DECLARE. Any variables you want to declare must be between AS and BEGIN in the procedure.
Your procedure should look like follows:
CREATE OR REPLACE PROCEDURE sp_testmyproc AS
--DECLARE
job_name varchar(100);
status_key number;
status_desc varchar(100);
notes varchar(250);
BEGIN
status_key := 1;
.....
.....
.....
Refer to this document for the syntax of the oracle procedure as it is very easy to follow.
Please note the difference when creating a stored procedure in SQL*Plus:
SQL> create or replace procedure test_ok as
2 v number;
3 begin
4 v:=0;
5 end;
6 /
Procedure created.
SQL> show errors
No errors.
SQL> create or replace procedure test_ko as
2 declare
3 v number;
4 begin
5 v:=0;
6 end;
7 /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE TEST_KO:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1 PLS-00103: Encountered the symbol "DECLARE" when expecting one of
the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior external language
SQL>
If you have compilation errors you get at least Warning: Procedure created with compilation errors. If you have compilation errors and use show errors you get all error messages.
I made a procedure which takes value and makes table which is:
create or replace procedure offc.temp(data1 varchar2(200)) is
var1 varchar2(4000);
BEGIN
var1:='create table offc.temp'||data1||'(
id number)';
EXECUTE IMMEDIATE var1;
end;
I got error when I made the procedure :
[Warning] ORA-24344: success with compilation error
1/35 PLS-00103: Encountered the symbol "(" when expecting one of the following:
:= . ) , # % default character
The symbol ":=" was substituted for "(" to continue.
(11: 0): Warning: compiled but with compilation errors
Why is this error coming as I want to create table by passing value to procedure.
You can't put the length in the parameter types
create or replace procedure offc.temp(data1 varchar2) is
var1 varchar2(4000);
BEGIN
var1:='create table offc.temp'||data1||'(
id number)';
EXECUTE IMMEDIATE var1;
end;
I'm trying to create a procedure to get the data from different columns of different tables. I have written this code but I get error PLS-00103: Encountered the symbol "DECLARE" when expecting one of
the following:
begin function package pragma procedure subtype type use
form
current cursor external language
The symbol "begin" was substituted for "DECLARE" to continue. can anybody
create or replace procedure List_of_mfi
(
cq out sys_refcursor
)
as
begin
open cq for SELECT a.mfi_name,
b.mfi_type_name,
c.mfi_tier_name,
d.mfi_state_name,
e.mfi_district_name,
a.mfi_phone_no
FROM mfi_master a,
mfi_type_master b,mfi_tier_new c,mfi_state_master d,mfi_district_master e
WHERE a.mfi_type_id = b.mfi_type_id(+)
and a.mfi_tier_id = c.mfi_tier_id(+)
and a.mfi_state_id = d.mfi_state_id(+)
and a.MFI_DISTRICT_ID=e.MFI_DISTRICT_ID(+);
end;
declare
cq sys_refcursor;
mfi_name varchar2(150);
mfi_type_name varchar2(150);
mfi_tier_name varchar2(150);
mfi_state_name varchar2(150);
mfi_district_name varchar2(150);
mfi_phone_no varchar2(150);
--SELECT a.mfi_name, b.mfi_type_name, c.mfi_tier_name, d.mfi_state_name,e.mfi_district_name, a.mfi_phone_no
begin
List_of_mfi(cq);
loop
fetch cq into mfi_name,mfi_type_name,mfi_tier_name,mfi_state_name,mfi_district_name,mfi_phone_no;
EXIT WHEN cq%NOTFOUND;
--print
dbms_output.put_line('mfi_name:'||mfi_name);
dbms_output.put_line('mfi_type_name:'||mfi_type_name);
dbms_output.put_line('mfi_tier_name:'||mfi_tier_name);
dbms_output.put_line('mfi_state_name:'||mfi_state_name);
dbms_output.put_line('mfi_district_name:'||mfi_district_name);
dbms_output.put_line('mfi_phone_no:'||mfi_phone_no);
end loop;
end;
Since I'm a beginner I do not know if this code is correct or wrong. I want to find out how to edit this and make it work using oracle reports builder.Thanks everyone.
end;
declare
You must put forward slash "/" after the END keyword to terminate the procedure block before you execute another PL/SQL anonymous block.
Put "/" after each END:
END;
/
I am a new PL/SQL user. I tried to create a procedure and run it like:
create or replace procedure addp1(i in number) is
begin
insert into t3 values (i,'xxxx');
end addp1;
begin
addp1(99);
end;
but i got error: Error(7,1): PLS-00103: Encountered the symbol "BEGIN" in my log file. Can anyone help me fix this problem.
Thanks
create or replace procedure addp1(i in number)
is
begin
insert into t3 values (i,'xxxx');
end addp1;
/* We have to actually push the block to the engine by issuing a '/' */
/
begin
addp1(99);
end;
/* Every PL/SQL Block needs this! */
/
My oracle procedure structure,
CREATE OR REPLACE PACKAGE BODY NLS_ADMIN."MY_PKG"
AS
PROCEDURE DATA_PRC (oresult OUT NUMBER )
IS
varKeyValue varchar2(1);
BEGIN
...
...
END;
I tried to call above procedure by executing below statement,
declare
oresult NUMBER;
begin
EXECUTE DATA_PRC(oresult);
end;
But getting below exception. Please help me how to call this procedure.
ORA-06550: line 8, column 9:
PLS-00103: Encountered the symbol "DATA_PRC" when expecting one of the following:
:= . ( # % ; immediate
The symbol ":=" was substituted for "DATA_PRC" to continue.
Simply this:
declare
oresult NUMBER;
begin
MY_PKG.DATA_PRC(oresult);
end;