Home » SQL & PL/SQL » SQL & PL/SQL » Comparing variables vs table records
Comparing variables vs table records [message #198570] Tue, 17 October 2006 13:25 Go to next message
superoscarin@hotmail.com
Messages: 101
Registered: July 2006
Location: Mexico
Senior Member

Hi

if i have 3 variables... and i want to compare them (the union of the 3) vs a table with this fields.

For example:

Values of my variables
v1=11
v2=22
v3=33

table

f1, f2, f3
11 22 33---> this means that the record exist; then i dont want to insert the record

Thanks
AlexOM
Re: Comparing variables vs table records [message #198574 is a reply to message #198570] Tue, 17 October 2006 14:10 Go to previous messageGo to next message
biohazardbill
Messages: 57
Registered: March 2006
Member
If v1||v2||v3 = f1||f2||f3
then --***insert statement here***-- end if;
Re: Comparing variables vs table records [message #198576 is a reply to message #198574] Tue, 17 October 2006 14:17 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
I think we're looking for something more like:

insert into t (f1, f2, f3)
  select v1, v2, v3
    from dual
   where not exists (select null
                       from t
                      where f1 = v1
                        and f2 = v2
                        and f3 = v3);

or if there is a unique or PK constraint on these columns:

begin
  insert into t (f1, f2, f3) values (v1, v2, v3);
exception
  when dup_val_on_index then
    null;
  when others then
    raise;
end;
Re: Comparing variables vs table records [message #198804 is a reply to message #198576] Wed, 18 October 2006 10:55 Go to previous message
superoscarin@hotmail.com
Messages: 101
Registered: July 2006
Location: Mexico
Senior Member

thanks guys
Previous Topic: how to determine a lock
Next Topic: SQL Script
Goto Forum:
  


Current Time: Tue Dec 03 18:35:16 CST 2024