In sqlplus I created the procedure, whitch fill my table GeneratedData with int values...
create procedure fillGeneratedData (x in int) as
begin
for i in 1..x loop
insert into GeneratedData values (i);
end loop;
end;
/
I want to create job, whitch call this procedure, but it throws errors and dont call the procedure...
BEGIN
sys.dbms_scheduler.create_job(
job_name => 'job1',
job_type => 'PLSQL_BLOCK',
job_action => 'begin exec fillGeneratedData(50000); end;',
repeat_interval => 'FREQ=MINUTELY;INTERVAL=2',
start_date => systimestamp at time zone 'Europe/Belgrade',
auto_drop => FALSE,
enabled => TRUE);
END;
sqlplus says PL/SQL procedure successfully completed, but when i look to alert log, it throw error:
Tue Apr 01 00:50:45 2014
Errors in file c:\app\adbsuser\diag\rdbms\orcl\orcl\trace\orcl_j000_7516.trc:
ORA-12012: error on auto execute of job 74677
ORA-06550: line 1, column 734:
PLS-00103: Encountered the symbol "" when expecting one of the following:
:= . ( # % ;
The symbol ";" was substituted for "" to continue.
Errors in file c:\app\adbsuser\diag\rdbms\orcl\orcl\trace\orcl_j000_7516.trc:
ORA-12012: error on auto execute of job 74679
ORA-06550: line 1, column 734:
PLS-00103: Encountered the symbol "FILLGENERATEDDATA" when expecting one of the following:
:= . ( # % ;
The symbol ":=" was substituted for "FILLGENERATEDDATA" to continue.
Can somebody help me?
Thanks a lot.
To start with, you PL/SQL block is not valid. If you tried to run just this
begin
exec fillGeneratedData(50000);
end;
you'd get an error. You don't use exec in a PL/SQL block-- that's a SQL*Plus command. Your PL/SQL block would just be
begin
fillGeneratedData(50000);
end;
Related
Out of curiosity I'm attempting to use the COMMENT statement in a PL/SQL block. I'm using Oracle APEX 18.2 on an Oracle 11g database and in SQL Workshop I am able to execute the command by itself, but if I wrap it in a BEGIN ... END block then I get an error message like:
ORA-06550: line 4, column 18: PLS-00103: Encountered the symbol "ON" when expecting one of the following: : = . ( # % ;
Example of command that works:
COMMENT ON COLUMN employees.job_id IS 'comment';
Example of command that results in the error message:
BEGIN
COMMENT ON COLUMN employees.job_id IS 'comment';
END;
I assume that COMMENT isn't a permitted statement in a stored procedure but I haven't been able to find evidence to back this up. Am I correct and if so is this documented anywhere?
Thanks to #GMB for an answer with written example.
Consider:
create table employees(job_id int);
begin
comment on column employees.job_id is 'comment'
end;
/
ora-06550: line 2, column 13:
pls-00103: encountered the symbol "on" when expecting one of the following:
:= . ( # % ;
begin
execute immediate 'comment on column employees.job_id is ''comment''' ;
end;
/
1 rows affected
db<>fiddle here
I'm trying to create reschedule procedure for AQ queues. So i have created procedure with one IN parameter where our operator will enter just a name of queue, and i hit error when i execute create of procedure
CREATE OR REPLACE PROCEDURE RESCHEDULE1 (p_queue IN VARCHAR2)
AS
BEGIN
SYS.DBMS_AQADM.STOP_QUEUE (p_queue);
END;
DECLARE
CURSOR upit
IS
SELECT destination
FROM USER_QUEUE_SCHEDULES
WHERE qname = p_queue;
BEGIN
FOR dest_rec IN upit
LOOP
DBMS_AQADM.UNSCHEDULE_PROPAGATION (queue_name => p_queue,
destination => dest_rec.destination);
DBMS_AQADM.SCHEDULE_PROPAGATION (queue_name => p_queue,
destination => dest_rec.destination,
start_time => SYSDATE);
END LOOP;
END;
;
BEGIN
SYS.DBMS_AQADM.START_QUEUE (p_queue);
END;
/
Error is
ORA-06550: line 7, column 39:
PL/SQL: ORA-00904: "P_QUEUE": invalid identifier
ORA-06550: line 5, column 4:
PL/SQL: SQL Statement ignored
ORA-06550: line 14, column 54:
PLS-00201: identifier 'P_QUEUE' must be declared
ORA-06550: line 14, column 2:
PL/SQL: Statement ignored
ORA-06550: line 17, column 52:
PLS-00201: identifier 'P_QUEUE' must be declared
ORA-06550: line 17, column 2:
PL/SQL: Statement ignored
p_queue is out of scope everywhere, except in RESCHEDULE1 procedure. You have to pass its value, somehow.
One option is this: instead of using an anonymous PL/SQL blocks, switch to procedures (and - of course - declare the p_queue parameter).
I think your procedure has improper use of BEGIN..END and DECLARE
Try following code:
CREATE OR REPLACE PROCEDURE RESCHEDULE1 (p_queue IN VARCHAR2)
AS
-- all declarations should go here
CURSOR upit
IS
SELECT destination
FROM USER_QUEUE_SCHEDULES
WHERE qname = p_queue;
BEGIN -- starting of procedure
BEGIN -- starting of this block -- can be removed
SYS.DBMS_AQADM.STOP_QUEUE (p_queue);
END; -- ending of this block -- can be removed
FOR dest_rec IN upit -- loop started from here
LOOP
DBMS_AQADM.UNSCHEDULE_PROPAGATION (queue_name => p_queue,
destination => dest_rec.destination);
DBMS_AQADM.SCHEDULE_PROPAGATION (queue_name => p_queue,
destination => dest_rec.destination,
start_time => SYSDATE);
END LOOP; -- loop ends here
BEGIN -- starting of this block -- can be removed
SYS.DBMS_AQADM.START_QUEUE (p_queue);
END; -- ending of this block -- can be removed
END RESCHEDULE1; -- end of procedure
/
Note: You can remove unnecessary BEGIN and END from code if you dont want to handle exceptions.
I have kept all BEGIN and END in procedure as it is, considering tht you actually need it for future development.
Cheers!!
Please sorry i didnt post that i have found answer, problem was with bad begin and end. Now this works
CREATE OR REPLACE PROCEDURE AQADMIN.RESCHEDULE1 (p_queue in varchar2)
is
begin
begin
DBMS_AQADM.STOP_QUEUE(p_queue);
end;
declare
cursor upit
is
SELECT destination
FROM USER_QUEUE_SCHEDULES
WHERE qname = p_queue ;
begin
for dest_rec in upit
loop
DBMS_AQADM.UNSCHEDULE_PROPAGATION (queue_name => p_queue,
destination => dest_rec.destination);
DBMS_AQADM.SCHEDULE_PROPAGATION (queue_name => p_queue,
destination => dest_rec.destination,
start_time => SYSDATE);
end loop;
end;
begin
DBMS_AQADM.START_QUEUE (p_queue);
end;
end;
/
Thank you for all your help!
my goal is to run a select to a table and based on the certain rows dynamically create an audit trail or policy on them.
so..
create a set_policy function that gets called/Looped:
create or replace
function set_policy
( sch VARCHAR2 ,
tab VARCHAR2,
colm VARCHAR2,
pred VARCHAR2,
emailer VARCHAR2
)
return VARCHAR2 is
policy_sql_stmt varchar2(1000);
BEGIN
policy_sql_stmt :=
'BEGIN
SYS.DBMS_FGA.ADD_POLICY (
object_schema => :s,
object_name => :t,
policy_name => ''CHK_:s_:t'',
audit_column => :c,
audit_condition => :p,
handler_schema => ''SYSADMIN_FGA'',
handler_module => '''||emailer||'(:s,:t,''''CHK_:s_:t'''')'',
enable => TRUE,
statement_types => ''SELECT, UPDATE'',
audit_trail => SYS.DBMS_FGA.DB + SYS.DBMS_FGA.EXTENDED);
END;';
--DBMS_OUTPUT.PUT_LINE('policy_sql_stmt = :' || policy_sql_stmt);
BEGIN
EXECUTE IMMEDIATE policy_sql_stmt USING sch,tab,colm,pred;
--EXECUTE IMMEDIATE policy_sql_stmt USING pred;
EXCEPTION
WHEN OTHERS THEN
BEGIN
--dbms_output.put_line('set_policy error code: '||SQLCODE);
--dbms_output.put_line(DBMS_UTILITY.FORMAT_CALL_STACK);
RETURN ('set_policy error code: '||SQLCODE);
END;
END;
RETURN 'success';
END;
Then a procedure that calls the function...
CREATE OR REPLACE PROCEDURE audit_slac_tables
AS
--DECLARE
emailer VARCHAR2(40):='audit_email_alert';
isSuccess VARCHAR2(40);
CURSOR myCursor
IS
SELECT SCHEMA AS sch,
TABLE_NAME AS tab,
FILTER_COLUMN AS colm,
WHERE_COND AS pred
FROM SLAC_REDACTION_TABLE slac;
--WHERE slac.table_name IN ('RECIPIENT','CARD');
BEGIN
FOR curRec IN myCursor
LOOP
BEGIN
--emailer := getEmailer(curRec.sch ,curRec.tab);
isSuccess := set_policy(curRec.sch ,curRec.tab, curRec.colm, curRec.pred, emailer);
DBMS_OUTPUT.PUT_LINE('Proc isSuccess = :' || isSuccess);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Proc error code: '||SQLCODE);
dbms_output.put_line('Proc error msg: '||SQLERRM);
--dbms_output.put_line(DBMS_UTILITY.FORMAT_CALL_STACK);
--dbms_output.put_line('================================================');
CONTINUE;
END;
--dbms_output.put_line('================================================');
END LOOP;
COMMIT;
END audit_slac_tables;
if I call it...
exec AUDIT_SLAC_TABLES;
I get the following bewildering error
Error starting at line : 6 in command -
exec AUDIT_SLAC_TABLES
Error report -
ORA-06550: line 12, column 18:
PLS-00201: identifier 'SYS.DBMS_FGA' must be declared
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
ORA-06512: at "GAPLITE.SET_POLICY", line 51
ORA-06512: at "GAPLITE.AUDIT_SLAC_TABLES", line 27
ORA-06512: at line 1
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Why a reference problem where the script DBMS_FGA.ADD_POLICY never had a problem?
I can run this script ( listed 1st above ) but not dynamically... it loses trhe contextual reference to the SYS packages somehow ??
can you please check this for me
this is not working
do we need special utl_mail
no idea what this utl_mail is
create or replace
procedure check_stock_qty
begin
for r ( select inv_qoh from inventory
where qty = 0 )
loop
UTL_MAIL.send(sender => 'na#yahoo.com',
recipients => 'krn9#mail.ca',
subject => 'Test Mail',
message => (r.inv_qoh),
mime_type => 'text; charset=us-ascii');
end loop;
end;
BEGIN
dbms_scheduler.create_job (
job_name => 'stock check',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN check_stock_qty; END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=minutely; interval=7200; bysecond=0;',
end_date => NULL,
enabled => TRUE,
END;
my error is
Error(2,1): PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: ( ; is with authid as cluster compress order using compiled wrapped external deterministic parallel_enable pipelined result_cache
The syntax for creating the procedure is
create or replace procedure <Name>
(<variable list>)
as (or is)
local variable declaration
begin
code section
exceptions
end;
here you missed the IS or AS Keyword before BEGIN
i tried with as
Error(5,8): PLS-00103: Encountered the symbol "(" when expecting one of the following: in The symbol "in" was substituted for "(" to continue.
Error(16,1): PLS-00103: Encountered the symbol "BEGIN"
Error(25,1): PLS-00103: Encountered the symbol "END" when expecting one of the following: ( - + case mod new not null continue avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe
so much errors :(
I created a procedure in Oracle but am getting an error when I attempt to execute it. Below are listed the steps I am taking to create this procedure:
SQL> ed getuserinfo
create or replace procedure getUserInfo
( p_username out Users.username%TYPE,
p_password out Users.password%TYPE ) IS
BEGIN
select username,password into p_username,p_password from users where username='yogi';
END;
/
SQL> exec getuserinfo
BEGIN getuserinfo; END;
*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'GETUSERINFO' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
What is the problem and how can I solve it? Olease can anyone help me?
You need to actually create the procedure, which you haven't done. You need a semi-colon after end and if you're creating it in SQL*Plus you need to add / to inform SQL*Plus that the block is finished:
create or replace procedure getUserInfo
( p_username out Users.username%TYPE,
p_password out Users.password%TYPE ) IS
BEGIN
select username,password into p_username,p_password from users;
END;
/
show error
It's always wise to add show error afterwards as well so that any errors are returned to the console in an understandable format.
Did you actually execute your create procedure statement? Did you get a "Procedure created." message? The fact that Oracle does not know of your getuserinfo procedure indicates to me that this statement was not performed.
I think it's procedure calling mistake!! Calling Should be like below:
SQL>var var1 varchar2(50);
SQL>var var2 varchar2(50);
SQL> exec getuserinfo(:var1, :var2);
SQL> print var1, var2;
Have Fun!!
You need to specify the out parameters when you call the procedure.
DECLARE
x Users.username%TYPE;
y Users.password%TYPE;
BEGIN
getuserinfo(x, y);
DBMS_OUTPUT.PUT_LINE('username: ' || x || ', password: ' || y);
END;