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.');

1 comment:

  1. Jadwal Sambung Ayam SV388 3 Maret 2019 - Minggu, Medan 3 Maret 2019 – Pada Hari Tersebut Akan Di Laksanakan Berbagai Pertandingan Sabung Ayam Secara Live di Arena Sabung Ayam Thailand.

    Situs Judi Sabung Ayam Online SV388 Merupakan Situs Judi Asal Thailand Yang Sangat Terkenal Dengan Permainan Sabung Ayam Yang Fair dan Menghibur Para Penonton Judi Sabung Ayam.

    Untuk Info Lebih Lanjut Bisa Hub kami Di :
    wechat : bolavita
    line : cs_bolavita
    whatsapp : +628122222995
    BBM: BOLAVITA

    ReplyDelete