Showing posts with label Automatic Table creation in Oracle Database. Show all posts
Showing posts with label Automatic Table creation in Oracle Database. Show all posts

Sunday 16 November 2014

Automatice Table creation with current date and time in Oracle Database

Solution:

Step1: Define a variable to keep date value with time

Declare
select_s VARCHAR2(2556);
v_sysdate VARCHAR2(10) := to_char(SYSDATE ,'MMDDYYYY:HH:MM');
BEgin
select_s := 'CREATE TABLE emp_'||v_sysdate||' AS SELECT * FROM scott.emp';

EXECUTE IMMEDIATE select_s;
COMMIT;
END;

Step2: Pass this program into a schedule to execute  

 -- Shell Script. 
 DBMS_SCHEDULER.create_program (
    program_name        => 'test_executable_prog',
    program_type        => 'EXECUTABLE',
    program_action      => '/u01/app/oracle/dba/table_backup.sh',
    number_of_arguments => 0,
    enabled             => TRUE,
    comments            => 'Program to backup table using a shell script.'); 

-- Create jobs.
BEGIN
  -- Job defined entirely by the CREATE JOB procedure.
  DBMS_SCHEDULER.create_job (
    job_name        => 'test_full_job_definition',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN DBMS_STATS.gather_schema_stats(''SCOTT''); END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date        => NULL,
    enabled         => TRUE,
    comments        => 'Job defined entirely by the CREATE JOB procedure.');