This is my code,
Declare
For num IN 1..10 LOOP
Continue When Mod(num,2)!=0;
DBMS_OUTPUT.PUT_LINE(num);
END LOOP;
END;
/
I am getting the following error:
SQL> # E:\dbms\f7.sql
For num IN 1..10 LOOP
*
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00103: Encountered the symbol "FOR" when expecting one of the following:
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursor
The symbol "begin" was substituted for "FOR" to continue.
ORA-06550: line 3, column 10:
PLS-00103: Encountered the symbol "WHEN" when expecting one of the following:
:= . ( # % ;
Please someone give me a working code so I can execute !!!
You don't need the declare block since you aren't declaring any variables, but you're missing the begin keyword:
BEGIN -- Here
FOR num IN 1..10 LOOP
Continue When Mod(num,2)!=0;
DBMS_OUTPUT.PUT_LINE(num);
END LOOP;
END;
/
Related
create or replace procedure testpga( psize number ) as
begin
declare
TYPE nAllotment_tabtyp IS TABLE OF char(2048) INDEX BY BINARY_INTEGER;
myarray nAllotmen_tabtyp;
begin
for i in 1.. psize_loop
myarray(i) := to_char(i);`bold`
end loop;
end;
enter code here
end;enter code here
/
LINE/COL ERROR
8/1 PLS-00103: Encountered the symbol "MYARRAY" when expecting one
of the following:
. ( * # % & - + / at loop mod remainder rem
<an exponent (**)> || multiset
The symbol "." was substituted for "MYARRAY" to continue.
8/12 PLS-00103: Encountered the symbol "=" when expecting one of the
following:
. ( * % & - + / at loop mod remainder rem <an exponent (**)>
|| multiset
LINE/COL ERROR
9/1 PLS-00103: Encountered the symbol "END" when expecting one of
the following:
begin function pragma procedure subtype type
current cursor delete
exists prior
create or replace procedure testpga( psize number )
as
TYPE nAllotment_tabtyp IS TABLE OF char(2048) INDEX BY BINARY_INTEGER;
myarray nAllotment_tabtyp;
begin
for i in 1.. psize
loop
myarray(i) := to_char(i); --'bold'
end loop;
end;
I suggest reading the PL/SQL Language Reference which is part of the Oracle database documentation and available online.
I am getting the error during executing the below procedure.
CREATE OR REPLACE PROCEDURE P_SUMIT (P_FEED IN FEED.FEED_ID%TYPE, P_OPCO_ID IN FEED.OPCO_ID%TYPE)
AS
BEGIN
DECLARE V_PCF_PATTERN FEED.PCF_PATTERN%TYPE;
DECLARE CURSOR C_FEED FOR SELECT PCF_PATTERN FROM FEED WHERE FEED_ID=P_FEED AND OPCO_ID=P_OPCO_ID;
OPEN C_FEED;
LOOP
FETCH C_FFED INTO V_PCF_PATTERN;
EXIT WHEN C_FEED%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(V_PCF_PATTERN);
END LOOP;
CLOSE C_FEED;
END;
Error logs :
3/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
The symbol "begin" was substituted for "DECLARE" to continue.
4/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
Please assist.
DECLARE statements should be after AS keyword.
CREATE OR REPLACE PROCEDURE P_SUMIT (P_FEED IN FEED.FEED_ID%TYPE, P_OPCO_ID IN FEED.OPCO_ID%TYPE)
AS
V_PCF_PATTERN FEED.PCF_PATTERN%TYPE;
CURSOR C_FEED IS SELECT PCF_PATTERN FROM FEED WHERE FEED_ID=P_FEED AND OPCO_ID=P_OPCO_ID;
BEGIN
OPEN C_FEED;
LOOP
FETCH C_FEED INTO V_PCF_PATTERN;
EXIT WHEN C_FEED%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(V_PCF_PATTERN);
END LOOP;
CLOSE C_FEED;
END P_SUMIT;
/
There's no need for an explicit cursor here, or for parameters to be prefixed with "p_". Implicit cursors are quicker and more robust to write, and perform better.
create or replace procedure p_sumit (
feed_id in feed.feed_id%type,
opco_id in feed.opco_id%type)
as
begin
for c_feed in (
select pcf_pattern
from feed
where feed_id = p_sumit.feed_id and
opco_id = p_sumit.opco_id)
loop
dbms_output.put_line(c_feed.pcf_pattern);
end loop;
end;
begin
Num NUMBER;
EXEC GwInwForceQueueUpdateUser
('ITSC1','A07','167321','22202244333','20091103','1','110',:num);
end;
Error on line 0
begin
Num NUMBER;
EXEC GwInwForceQueueUpdateUser
('ITSC1','A07','167321','222
got Error :
ORA-06550: line 2, column 5:
PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
:= . ( # % ;
ORA-06550: line 5, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function package pragma procedure subtype type use
form
current cursor
Your PL/SQL code should look like this:
declare
Num NUMBER;
begin
GwInwForceQueueUpdateUser('ITSC1','A07','167321','22202244333','20091103','1','110',num);
end;
DECLARE
data_line VARCHAR2(200); -- Data line read from input file
data_file UTL_FILE.FILE_TYPE; -- Data file handle
my_dir VARCHAR2(250); -- Directory containing the data file
my_filename VARCHAR2(50);
BEGIN
my_dir := 'c:\temp';
my_filename := 'Lab4AData.dat';
my_file := UTL_FILE.FOPEN(my_dir, my_filename, 'r');
LOOP;
UTL_FILE.GET_LINE(data_file, data_line);
EXCEPTION
WHEN no_data_found THEN
DBMS_OUTPUT.PUT_LINE('Finished');
exit;
END LOOP;
END;
/
The problem is I cannot even get this anonymous block of code started. To start, I'm just trying to open my data file and read it, then build from there. But I can't even get the file open.
SQL Developer Error Report starts right off with
Error starting at line 5 in command:
DECLARE
then repeats the block of code and adds this:
ORA-06550: line 12, column 8:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
The symbol "exit" was substituted for ";" to continue.
ORA-06550: line 15, column 3:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
( begin case declare end exit for goto if loop mod null
pragma raise return select update while with <an identifier>
<a double-quoted delimited-i
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Try the following:
DECLARE
data_line VARCHAR2(200); -- Data line read from input file
data_file UTL_FILE.FILE_TYPE; -- Data file handle
my_dir VARCHAR2(250); -- Directory containing the data file
my_filename VARCHAR2(50);
BEGIN
my_dir := 'c:\temp';
my_filename := 'Lab4AData.dat';
data_file := UTL_FILE.FOPEN(my_dir, my_filename, 'r');
LOOP
UTL_FILE.GET_LINE(data_file, data_line);
-- add code to do something with data_line here
END LOOP;
EXCEPTION
WHEN no_data_found THEN
DBMS_OUTPUT.PUT_LINE('Finished');
UTL_FILE.FCLOSE(data_file);
END;
#ShannonSeverance's comments about using directory objects with UTL_FILE.FOPEN are appropriate, except in the instance where your DBA has not embraced their use and insists on sticking with the "tried and true" INIT.ORA parameter UTL_FILE_DIR. Don't ask me how I know... :-)
Share and enjoy.
i'm new to pl/sql and trying to print even numbers up till 100 using the following code:
Declare
i number;
sum number:=0;
x number:=2;
n number;
Begin
for i in 1..100 loop
if (i%x=0) then
n:=i;
sum:=sum+n;
end if;
end loop;
dbms_output.put_line(sum);
end;
i get this error
ERROR at line 10:
ORA-06550: line 10, column 12:
PLS-00103: Encountered the symbol "+" when expecting one of the following:
(
ORA-06550: line 13, column 26:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
(
Help? :(
There is no % operator in PL/SQL; use the mod(i,x) function instead. Anyway, you don't need the n variable. sum:=sum+i will do. sum might be a reserved word, use s instead.
\
Now:
Declare
i number;
sum number:=0;
Begin
for i in 1..100 loop
if (mod(i,2)=0) then
sum:=sum+i;
end if;
end loop;
dbms_output.put_line(sum);
end;
sameproblem :(
There is no % operator in PL/SQL; use the mod(i,x) function instead. Anyway, you don't need the n variable. sum:=sum+i will do. But: sum is a PL/SQL keyword, use s instead.
Declare
i number;
sum1 number:=0;
x number:=2;
n number;
Begin
for i in 1..100 loop
if(i mod x =0)then
n:=i;
sum1:=sum1+n;
end if;
end loop;
dbms_output.put_line(sum1);
end;
/
Reason :
The "sum" is one of the aggregate function ,so we can't use this as variable name.