We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

conditional statement for a nomber of records

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

2
Contributors
1
Reply
5 Days
Discussion Span
1 Year Ago
Last Updated
2
Views
munitjsr2
Light Poster
27 posts since Apr 2011
Reputation Points: 9
Solved Threads: 0
Skill Endorsements: 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;
seslie
Junior Poster
105 posts since Mar 2010
Reputation Points: 66
Solved Threads: 10
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0562 seconds using 2.64MB