Compiler error when using DBMS_OUTPUT.PUT_LINE - oracle

I using oracle developer tools for viusal studio to develop my pl/sql program,however,I encounter a problem with this simple code
Here is the code
BEGIN
DBMS_OUTPUT.PUT_LINE('helloWorld');
END;
the debug info as follow:
**ERROR
ORA-06550: line 1, column 6:
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> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge
<a single-quoted SQL string> pipe
<an alternatively-quoted SQL string>
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" 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
<an identifier> <a double-quoted delimited-id**

try:
DECLARE
v_var VARCHAR2(15) := 'helloworld';
BEGIN
DBMS_OUTPUT.PUT_LINE(v_var);
END;

Related

how to use refcursor?

I am trying to run an explain plan using a wrapper, but getting compilation error. Can you please help troubleshoot this error.
set serveroutput on
var my_cur refcursor;
begin
:my_cur:=sys.run_xplan('select * from hcc.Tab_A');
end;
/print my_cur
Error:
begin
:my_cur:=sys.run_xplan('select * from hcc.Tab_A');
end;
/print my_cur
Error report -
ORA-06550: line 4, column 1:
PLS-00103: Encountered the symbol "/" 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
<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
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.

Warning: Package Body created with compilation errors

Please check my package and procedures.
My package:
create or replace package transaction1 as
procedure enter_transaction(acc number, kind varchar2, amount number);
procedure apply_transaction;
end;
/
This is my body:
create or replace package body transaction1 as
procedure enter_transaction(acc in number, kind in varchar2, amount in number)
is
begin
end;
procedure apply_transaction
is
begin
end;
end;
/
What is the warning? Why?
If you see a warning: Errors: check compiler log
then run show errors command and you will see the error log :
7/5 PLS-00103: Encountered the symbol "END" 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
14/5 PLS-00103: Encountered the symbol "END" 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
In case of your package body Oracle complains because BEGIN END blocks don't contain any commands.
In Oracle the BEGIN-END block must contain at least one command. Could be NULL, if you don't want to run anything (and don't forget to place a semicolon after NULL command):
PROCEDURE ......
IS
BEGIN
NULL;
END;

Singleton Query Used In PL-SQL Condition (IF Statement)

I get the following error when trying to run my code:
BEGIN
IF((select count(*) from tablename where column = 'value') > 0) THEN
-- do stuff.
ELSE
-- do stuff.
END IF;
END;
Error:
ORA-06550: line 2, column 5:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
Obviously the error code makes no sense. I'm getting used to this when working with Oracle.
The COUNT() function exists in PL. What else could it be.
Lance Link is that you under cover? You can't have a query in an IF statement. First do the query as a select INTO a variable, then test the variable:
DECLARE
v_count number;
BEGIN
select count(*)
into v_count
from tablename
where column = 'value';
IF ( v_count > 0) THEN
-- do stuff.
ELSE
-- do stuff.
END IF;
END;
Give Mata my regards.

PLSQL - Error in associative array

Im trying to delete a set of tables and afterwards I want to recreate them using as select from. For couriousity I wanted to do this with an associative array. Unfortunately something is messed up, several errors appear and I can't find the reasons. This is the code:
DECLARE
TYPE t_tbl
IS
TABLE OF VARCHAR(100) INDEX BY VARCHAR2(100);
L_Tbl T_Tbl;
l_key VARCHAR2(100);
BEGIN
l_tbl('tableA') := 'table1';
l_tbl('tableB') := 'table2';
L_Tbl('tableC') := 'table3';
l_tbl('tableD') := 'table4';
l_key := l_tbl.first;
LOOP
BEGIN
EXIT WHEN L_Key IS NULL;
Dbms_Output.Put_Line('Dropping TABLE '|| L_Key ||);
EXECUTE Immediate 'DROP TABLE ' || L_Key;
dbms_output.put_line(l_key ||' '|| l_tbl(l_key));
-- Catch exception if table does not exist
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
Raise;
END IF;
EXECUTE IMMEDIATE 'create table schema1.' ||l_key||' as select * from schema2.'||l_tbl(l_key)||;
l_key := l_tbl.next(l_key);
END LOOP;
End;
END;
I get these errors:
ORA-06550: line 17, column 56:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
( - + case mod new null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current max min prior sql stddev sum
variance execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternatively-quoted SQL
ORA-06550: line 26, column 102:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current max min prior sql stddev su
ORA-06550: line 29, column 6:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
loop
The symbol "loop" was substituted for ";" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Could someone give me a hint please? Thank you in advance!
You have some unterminated append operations || on lines:
Dbms_Output.Put_Line('Dropping TABLE '|| L_Key ||);
And
EXECUTE IMMEDIATE 'create table schema1.' ||l_key||' as select * from schema2.'||l_tbl(l_key)||;
Get rid of the || at the end.
Also the way you are using LOOP is incorrect. Refer example:
while elem is not null loop
dbms_output.put_line(elem || ': ' || var_assoc_varchar(elem));
elem := var_assoc_varchar.next(elem);
end loop;
Remove || at the end of the line in line 17 and line 25.
And also ending loop before ending the block begin....end. get begin before loop or get end before end loop.
l_key := l_tbl.next(l_key);
END LOOP;
END;

Error is occurring during execution of procedure in oracle

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;

Resources