I run this command :
select * from LIST where JCODE = 8 and
KCODE = 01 and LCODE = 2011
and if the above retruns no rows then perform the below :
insert into LIST
select * from LIST@LNDB where JCODE = 8 and
KCODE = 01 and LCODE = 2011 and ban
in (select BAN from billing_account)
Update LIST set STS = null where JCODE = 8
AND KCODE = 01;
Update LIST set NO = '1' where JCODE = 8 AND
KCODE = 01;
moreover can i use some variable in the begininng which
sets
JCODE= somevalue
KCODE= anothervalue
LCODE=someothervalue
so that i dont have to edit every line every time i run it.
I am using :
Oracle 9i Enterprise Edition release 9.2.8.0 - 64 bit Production
I can’t tell for the
SELECT, but you should be allowed toUPDATEseveral fields at once:Edit: I don’t understand why you need the second
SELECT(withLIST@LNDB), but in both queries I don’t think you really need all the fields, so instead of usingSELECT *, which is heavy for the system, use only and explicitly the primary key’s field name (likeSELECT id FROM ...).And there is a way to do it in one request, probably something like:
This way, if there is no result found by
SELECT, theWHEREclause inUPDATEwill be false for every row, as 0<0 is false. There may also be a way to useCOUNT()with a named field instead of*, I don’t know Oracle enough for that.Re-edit: indeed, if your second
SELECTis actually anINSERT, you probably need that*🙂 But I don’t think you can apply the same trick on theINSERTas the one on theUPDATE…Re-re-edit: to write better what I put in the comment – taken from http://www.oradev.com/oracle_insert.jsp – your one and only request could be:
Naturally you can add the GuZzie touch, use
DECLARE,BEGINandENDto make the writing of parameters easier 😉