1
votes

I would like to create procedure to check if the records exists then updated else insert.However, there is an issue that I have tried to solve it but I cannot solve it.Please help.

CREATE TABLE JOB_RUN
(
DATE_KEY VARCHAR2(8),
JOB_NAME VARCHAR2(20),
START_DATE TIMESTAMP,
CTL_ROWS NUMBER,
LOAD_DATA_ROW NUMBER,
END_DATE TIMESTAMP,
FLAG_COMPLETED CHAR(1),
PRIMARY KEY (DATE_KEY,JOB_NAME)
);

Here is the sample value of the fields:

INSERT INTO JOB_RUN(DATE_KEY,JOB_NAME,START_DATE,CTL_ROWS,LOAD_DATA_ROW,END_DATE, FLAG_COMPLETED)
        VALUES('20110101','TABLE_NAME',SYSDATE,10,0, NULL, 'N');

Then, I have created the Procedure to receive date_key and job_name

create or replace procedure check_job(pdate IN varchar2,pname IN varchar2) as
declare
v_count int;
    begin
        select count(*) into v_count from MISDBA.job_run where (date_key=pdate and job_name=pname);
        if v_count = 1 then
            update job_run
            set start_date=sysdate,ctl_rows=5;
        else         
        insert into misdba.job_run(date_key,job_name,start_date,ctl_rows,load_data_row,end_date, flag_completed)
        values(pdate,pname,sysdate,10,0, null, 'N');
        end if;
        commit;
    end;

After that I run this below query to call PROCEDURE

BEGIN
EXECUTE CHECK_JOB('20200101','table2');
END;

I got this error:

SQL Error [6550] [65000]: ORA-06550: line 2, column 9: PLS-00103: Encountered the symbol "CHECK_JOB" when expecting one of the following:

:= . ( @ % ; immediate The symbol ":=" was substituted for "CHECK_JOB" to continue. java.sql.SQLException: ORA-06550: line 2, column 9: PLS-00103: Encountered the symbol "CHECK_JOB" when expecting one of the following::= . ( @ % ; immediate The symbol ":=" was substituted for "CHECK_JOB" to continue.

1
Not related to the error(s) you are getting, but is your update supposed to have the same filter conditions as the select count(*)?Alex Poole

1 Answers

2
votes

You have to remove the EXECUTE:

BEGIN
 CHECK_JOB('20200101','table2');
END;