how to use refcursor? - oracle

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.

Related

Getting error - "Encountered the symbol " " when expecting one of the following" while creating Job

I am getting below error while creating new job.
Error report -
ORA-06550: line 2, column 2:
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
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
This is the code that I am using for creating Job. Can you please help me in that.
BEGIN
  DBMS_SCHEDULER.create_job (
    job_name        => 'P_DELETE',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN ADMIN.DELETE_REG; COMMIT; END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'FREQ=WEEKLY; BYDAY=FRI; BYHOUR=3; ',  
    enabled         => TRUE);
END;
Please help!
PLS-00103: Encountered the symbol " " when expecting one of the following:
I think the problem is in your repeat_interval argument.
The ; is used to separate different period elements, with no semi-colon after the last element. However, your string ends '; ' which explains why Oracle hurls.
The solution would be to pass this instead:
repeat_interval => 'FREQ=WEEKLY; BYDAY=FRI; BYHOUR=3'

How do I handle the exception in this pl/sql for loop correctly?

First off, I'm a relative newbie to PL/SQL so I might be missing something trivial.
Here is a snippet of code that I'm having issues with running -
FOR indx IN 1 .. arr.COUNT
LOOP
SELECT COUNT(*), ca.cities
INTO tmp_count, affected_cities
FROM PDB.utilities ca
WHERE (ca.app_city_id = cityid
AND ca.app_plumbing_id = arr(indx))
AND( BITAND(options1,2) = 2
OR BITAND(options1,1) = 1)
GROUP BY ca.cities;
IF tmp_count >=0 THEN
-- We have an affected app so collect metrics
IF plumbings(indx_mv) ='0Ci30000000GsBN' THEN
count_wrigley:= count_wrigley+tmp_count;
END IF;
counter:= counter+tmp_count; --overall count.
tmp_count:=0;
affected_cities:=null;
END IF;
EXCEPTION -- error thrown here !
WHEN NO_DATA_FOUND THEN
CONTINUE;
END;
END LOOP; -- Error thrown here too.
And here is my error trace -
Error report:
ORA-06550: line 64, column 13:
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-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
ORA-06550: line 68, column 11:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
;
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
It's worth noting that the block fails only with the exception handling and compiles successfully otherwise. So my guess is I'm doing something wrong there?
Any help would be greatly appreciated! Thanks
EXCEPTION aligns with BEGIN ... END blocks. There is no BEGIN inside your loop, so there should be no exception either.
It seems the purpose of the exception is to suppress NO_DATA_FOUND errors inside the loop. So to fix this error you need to put a BEGIN / END block in the loop too. (Ah, you have an END just no BEGIN - your code would hurl with the EXCEPTION block).
FOR indx IN 1 .. arr.COUNT
LOOP
BEGIN
SELECT COUNT(*), ca.cities
INTO tmp_count, affected_cities
FROM PDB.utilities ca
....
EXCEPTION
WHEN NO_DATA_FOUND THEN
CONTINUE;
END;
END LOOP;

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;

Compiler error when using DBMS_OUTPUT.PUT_LINE

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;

PL/SQL UTL_FILE read trouble on anonymous block

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.

Resources