1,105,254 Community Members

conditional statement for a nomber of records

Member Avatar
munitjsr2
Light Poster
28 posts since Apr 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

have got this update script updating certain columns

update oppar
set oppar_run_mode = 0,
    oppar_run_time = 0, 
    oppar_interval_ind = 'N' , 
    oppar_destination = '',
    oppar_run_date ='', 
    oppar_run_interval=''
    where ( oppar_job_name, oppar_job_rec ) 
    in 
     ( ('CSCLM' , 'XYZ')
   , ('ARCLEVEXT' , 'LMN'));

But there are cases where there is no record in the table oppar where the column oppar_job_rec is XYZ or LMN.

Now I need to verify the existence of oppar_job_name=CSCLM then if that exists i need to check the existence of the Job rec coresponding to CSCLM i.e oppar_job_rec=XYZ and if it does not exists i need to add a new record with these details.

oppar_job_name=CSCLM
oppar_job_rec=XYZ
oppar_run_mode = 0
oppar_run_time = 0
oppar_interval_ind = 'N'
oppar_destination = ''
oppar_run_date =''
oppar_run_interval=''

if it exists then i need to update that row.

please help and tell me if you need more info.

but how do i perform the checking if it could be done and i need to do this on about 100 records with different values for oppar_job_rec .

Orcale9i Enterprise editon release 9.2.8.0 - 64 bit Production

Member Avatar
seslie
Junior Poster
105 posts since Mar 2010
Reputation Points: 56 [?]
Q&As Helped to Solve: 13 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi munitjsr2,

So, let me see if i get you right.

You have a table: Oppar that needs to be updated based on the script..

But there are cases where there is no record in the table oppar where the column oppar_job_rec is XYZ or LMN.

You would need a particular column to identify an 'empty' record. I assume every other column in the table will be null except for the job_name, job_rec and probably the primary key.

Now I need to verify the existence of oppar_job_name=CSCLM then if that exists i need to check the existence of the Job rec coresponding to CSCLM i.e oppar_job_rec=XYZ and if it does not exists i need to add a new record with these details.

DECLARE
  cnt NUMBER;
BEGIN
  SELECT COUNT (*)
  INTO cnt
  FROM oppar
  WHERE oppar_job_name = 'CSCLM' and oppar_job_rec = 'XYZ'
  or oppar_job_name = 'ARCLEVEXT' and oppar_job_rec = 'LMN'
  AND [I]particular_column[/I]= NULL

 IF (cnt > 0)
 THEN

   //UPDATE TABLE

 ELSE

  //INSERT INTO TABLE 

ENDIF;
END;
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: