-1

I am trying to create a scheduled job in Oracle SQL Developer that would run once a month and I am testing the Scheduler/Jobs feature where I have created a simple SQL query to test the ability to do this. I have a simple table called "TEST123" and I can see that it works when I do "SELECT * FROM TEST123;".

In SQL Developer I have a Job called "TEST1" which has a PL/SQL Block = "DROP TABLE TEST123;" to run immediately (though I have also tested this with running at a specific time).

After I see that I can still select from this test table and that the STATE of the job name is "FAILED". I left all other settings as default. What am I missing here? Why is it failing and is there a way to fix it?

SQL From Job Wizard:

BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
            job_name => '"TEST1"',
            job_type => 'PLSQL_BLOCK',
            job_action => 'DROP TABLE MKTRD.TEST123;',
            number_of_arguments => 0,
            start_date => NULL,
            repeat_interval => NULL,
            end_date => NULL,
            enabled => FALSE,
            auto_drop => FALSE,
            comments => '');

    DBMS_SCHEDULER.SET_ATTRIBUTE( 
             name => '"TEST1"', 
             attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_OFF);
  
    DBMS_SCHEDULER.enable(
             name => '"TEST1"');
END;

Error from Job Log:

 "ORA-06550: line 1, column 757:
PLS-00103: Encountered the symbol "DROP" 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
   json_exists json_value json_query json_object json_array
The symbol "lock was inserted before "DROP" to continue.
ORA-06550: line 1, column 781:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

   . , @ in <an identifier>
   <a double-quoted delimited-identifier> partition subpartition
ORA-06550: line 1, column 856:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   end not pragma final instantiable order overriding static
   member constructor map
"

Update: If I use the PLSQL Block syntax of

BEGIN
  DROP TABLE TEST123;
END

I still get an error of:

"ORA-06550: line 2, column 3:
PLS-00103: Encountered the symbol "DROP" 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
   json_exists json_value json_query json_object json_array
The symbol "lock was inserted before "DROP" to continue.
ORA-06550: line 2, column 27:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

   . , @ in <an identifier>
   <a double-quoted delimited-identifier> partition subpartition
"
4
  • Why would you even be trying to create a schedule job just to drop a table? Creating and dropping tables should be so infrequent that there is no reason not to just connect to the database (sqlplus, SQL Dev) and issue the DROP manually. Trying to do it in a scheduled job suggests a serious design flaw in.
    – EdStevens
    Commented Sep 26, 2020 at 12:53
  • Okay. This is just a test example. The real schedule that I am trying to implement could start work a drop or a deleted all records and insert new records based off results of a query. In essence I have a table that needs to be updated one a month but the query takes a while and I want to automate the task. This is just one of at least a dozen task that id like to do this for but if the fundamentals aren't working then I can't do the more complex ones as well. I was trying to keep it simple for troubleshooting. Commented Sep 26, 2020 at 15:03
  • Your example should reflect the nature of what you are trying to achieve. DROP TABLE is a DDL statement. INSERT/UPDATE/DELETE are DML statements. They are handled much differently in PL/SQL. Give us an example of the failure using code that represents what you are actually trying to do.
    – EdStevens
    Commented Sep 26, 2020 at 15:22
  • Turns out the issues is with the DDL vs DML statement and the fact that I wasn't able to putting a ';' after the END. Commented Sep 26, 2020 at 15:37

2 Answers 2

1

Here is the correct an answer to your reddit post by reddit user 'beunbehagen'

I believe you cannot do DDL commands in a PL\SQL block. To do it would need to use "execute immediately "

Execute immediately 'drop table <tableName>';

Also, be warned, plsql blocks normally don't run with permissions granted by roles (like dba).

3
  • Thank you that first part was useful. Turns out if I use DML and DDL then it works. A big part that was also missing is the after the END it requires a ';' to run. Commented Sep 26, 2020 at 15:36
  • @AndrewHicks Sorry, this was my mistake. I hope now it is correct
    – miracle173
    Commented Sep 26, 2020 at 18:06
  • Nothing to apologize for. Just was seeking help to figure out the issue. Commented Sep 26, 2020 at 18:10
0

Thank you everyone for your feedback, turns out that there is an issue with trying to schedule jobs for DDL statements. I tried changing it from this:

BEGIN
  DROP TABLE TEST123;
END

To this:

BEGIN
  DELETE FROM TEST123;
END

And ran into a new issues. Turns out I need to have a ';' after the END as well. So when I did this it did work:

BEGIN
  DELETE FROM TEST123;
END;

Not the answer you're looking for? Browse other questions tagged or ask your own question.