in reply to Update/insert record in database

Does the database you are using support stored procedures?
If so you would probably want to do what you are talking about
in a stored procedure that would be executed from your script. In PL/SQL:
procedure ins_or_upd ( s varchar2 ... ) is begin update ... where column=s; if SQL%rowcount = 0 then insert ... end if; end;

Replies are listed 'Best First'.
Re: Re: Exists
by SamueD2 (Novice) on Apr 11, 2003 at 18:48 UTC
    I have twenty five fields (scalars)that I am reading from the file per line . How do I pass the variables to the stored procedure in my perl script. Thanks
      That depends on the DBMS you are using. I know Oracle so I can only
      tell you how to go about this with PL/SQL.
      In PL/SQL your could have a stored function that could tell your script if a record exist or not so that your script could choose either to do a insert or an update. You could also just use a stored procedure like the one I mentioned earlier and just add your fields to the parameter list. You could also do everything from your script. Your script could do the update and if the row count is zero that means your script needs to do an insert.
        Below is the script that I have. I like the idea of using a stored procedure. But I dont know how to bind my scalar to a param and how do I call the stored procedure. The database i am using is MS SQL SERVER. Thanks for your help