0

this is my requirement .i want fetch the record from one table and store it in another temporary table.i wrote as query.but dont know how to make it as procedure by declaring varibales and so.

Daily new customers data will gets inserted in table.I only want to fetch the customer data who signed attribute_value as 'TOY_GIFT' from last 10 to till today's date. i want to run this as procedure for every 10 days.

CREATE 
OR 
INSERT INTO
   cst_cust_attributes_tmp (ORGANIZATION_ID, CUST_ID, ATTRIBUTE_ID, ATTRIBUTE_SEQ, ATTRIBUTE_VALUE, ACTIVE_FLAG, CREATE_DATE, CREATE_USER, UPDATE_DATE, UPDATE_USER) 
   SELECT
      ORGANIZATION_ID,
      CUST_ID,
      ATTRIBUTE_ID,
      ATTRIBUTE_SEQ,
      ATTRIBUTE_VALUE,
      ACTIVE_FLAG,
      CREATE_DATE,
      CREATE_USER,
      UPDATE_DATE,
      UPDATE_USER 
   FROM
      cst_cust_attributes 
   WHERE
      create_date between to_date(to_char(sysdate - 10, 'DD-MON-YYYY HH:MI:SS AM'), 'DD-MON-YYYY HH:MI:SS AM') and to_date(to_char(sysdate, 'DD-MON-YYYY HH:MI:SS AM'), 'DD-MON-YYYY HH:MI:SS AM') 
      and attribute_value = 'TOY_GIFT' ;

//

Thanks in advance..

1
  • 1
    "i wrote as query.but dont know how to make it as procedure by declaring varibales" You don't tell use what variables do you want to use. Please edit the question and give a minimal reproducible example with example data and your expected output and fully explain the problem.
    – MT0
    Commented Nov 9, 2021 at 11:40

1 Answer 1

1

You need to create a proc to insert records, and set up a dbms job to execute it every 10 days.

Like, procedure :

create or replace procedure LOAD_CUSTOMERS is
BEGIN
INSERT INTO
   cst_cust_attributes_tmp (ORGANIZATION_ID, CUST_ID, ATTRIBUTE_ID, ATTRIBUTE_SEQ, ATTRIBUTE_VALUE, ACTIVE_FLAG, CREATE_DATE, CREATE_USER, UPDATE_DATE, UPDATE_USER) 
   SELECT
      ORGANIZATION_ID,
      CUST_ID,
      ATTRIBUTE_ID,
      ATTRIBUTE_SEQ,
      ATTRIBUTE_VALUE,
      ACTIVE_FLAG,
      CREATE_DATE,
      CREATE_USER,
      UPDATE_DATE,
      UPDATE_USER 
   FROM
      cst_cust_attributes 
   WHERE
      create_date between to_date(to_char(sysdate - 10, 'DD-MON-YYYY HH:MI:SS AM'), 'DD-MON-YYYY HH:MI:SS AM') and to_date(to_char(sysdate, 'DD-MON-YYYY HH:MI:SS AM'), 'DD-MON-YYYY HH:MI:SS AM') 
      and attribute_value = 'TOY_GIFT' ;
      COMMIT;
END;

DBMS Job:

begin
  sys.dbms_scheduler.create_job(job_name            => 'LOAD_CUSTOMERS_JOB',
                                job_type            => 'STORED_PROCEDURE',
                                job_action          => 'LOAD_CUSTOMERS', -- YOUR PROC NAME
                                start_date          => to_date('05-12-2019 00:00:00', 'dd-mm-yyyy hh24:mi:ss'),
                                repeat_interval     => 'Freq=Daily;Interval=10',
                                end_date            => to_date(null),
                                job_class           => 'DEFAULT_JOB_CLASS',
                                enabled             => true,
                                auto_drop           => false,
                                comments            => '');
end;
2
  • iam a fresher.my company uses oracle 11g. iam new to Pl/sql.i know only basic sql.Iam not aware of the below things in oracle pl/sql ``` 1.creating procedures 2.creating jobs 3.api calling 4.batch running 5.metalized view 6.DB links 7.configuring mail alerts from Database. 8.all pl/sql concepts can u suggest me where to learn all this simple and easily.kindly suggest some best youtube channels,websites,best courses,ebooks or any platforms
    – Happy Man
    Commented Nov 9, 2021 at 15:21
  • happy udemy and youtube have great courses. Unfortunately i haf to learn by myself while i was junior at my first job. Commented Nov 9, 2021 at 18:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.