DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Plzz Help

  1. #1
    Join Date
    Jul 2003
    Posts
    53

    Plzz Help

    Hi,
    I need to check for the existence of record in a table for certain conditions if the record exits just update some muneric columns if it does not exists insert it
    can u send me the query on this

    Thanks all in advance
    Anupama
    anu

  2. #2
    Join Date
    Jan 2001
    Posts
    2,828
    Hi

    One way would be to do

    declare
    begin
    --do the update
    update table
    set col1=some_value
    where col2=some_condition; --based on some criteria
    --check wheather u updated any rows
    if sql%rowcount=0 then
    --do nothing
    NULL;
    else
    insert into tables
    values(some_value);
    end if
    end;

    regards
    Hrishy
    Last edited by hrishy; 03-04-2004 at 06:15 AM.

  3. #3
    Join Date
    Sep 2002
    Posts
    376
    Hi,

    Here is the Pseudocode, which u can try
    ----------------

    Procedure Populate_Target_table

    Cursor c1 is selet * from Target_Table
    MINUS
    select * from Source Table

    for x in c1 loop

    Insert into Target_Table
    By taking data from cursor;

    Exception
    Dup_val_on index

    Update Target_table


    You need to have a primary key for this to work

  4. #4
    Join Date
    Aug 2002
    Posts
    115

  5. #5
    Join Date
    Jul 2003
    Posts
    53
    Thanks all for your help the problem is solved
    anu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width