Monthly Archives: January 2009

Looking forward to 11g sequence expressions in PL/SQL

Although behind the scenes Oracle will perform a “select .nextval from dual” and therefore really doesn’t improve performance or anything I’m looking forward to write 11g PL/SQL code where you can use the sequence pseudo-columns CURRVAL and NEXTVAL in expressions. First off, I always prefer to use the .NEXTVAL in the SQL statement itself and use the RETURNING INTO clause to assign the new value to a PL/SQL variable. BUT, if the case requires for some reason to get the sequence value in PL/SQL without going through a SQL statement first just imagine how beautiful and elegant your code will look like without having “select .netxval into from dual;” spread all over the place…

SQL> create sequence seq;

-- the 10g and prior way
SQL> declare
  nextval number;
begin
  select seq.nextval
  into nextval
  from dual;
end;
/

-- the 11g way
SQL> declare
  nextval number;
begin
  nextval := seq.nextval;
end;
/

You can basically use the sequence pseudo-columns everywhere where a number value is valid in the expression, e.g. “…if seq.currval > 10 then…”

Export/Import Scheduler Jobs

The Oracle Utilities documentation (data pump, sql*ldr, etc.) is a bit light with regards to the object types and the corresponding names used in the INCLUDE parameter as it only refers to DATABASE_EXPORT_OBJECTS, SCHEMA_EXPORT_OBJECTS and TABLE_EXPORT_OBJECTS views which apparently do not have a very useful description in the COMMENTS column for all object paths.

On the web there are several resources showing how to import Oracle Scheduler jobs from a schema dump by creating the sql file (using SQLFILE parameter) and then extracting the relevant DBMS_SCHEDULER.CREATE_JOB commands from the DDL sql file. This seems a bit cumbersome to automate. Fortunately there is a much simpler way to do this using the right object type in the INCLUDE parameter: PROCOBJ

Assuming schema_dump.dmp contains a complete schema dump and you just want to import the Scheduler jobs run following impdp command:

$ impdp <username>/<password> dumpfile=schema_dump.dmp include=PROCOBJ

Foot note: All tests have been run on a 10g 10.2.0.4 database.