Iver Erling Arva
asked on
enter several value pairs into a oracle sql table using scripts
Hi!
I have several value pairs and want to use one value to find the correct row and then insert the other value into one of the columns in a table:
Thx!
IVer
I have several value pairs and want to use one value to find the correct row and then insert the other value into one of the columns in a table:
FOR ALL VALUES IN (LIST OF PAIRS)
UPDATE TABLE1
SET COL2=VAR2
WHERE COL1=VAR1
NEXT
Can someone please help me with this? Its probably very simple, but I don't know how to do it and I am in a bit of a rush... ;-)Thx!
IVer
Please provide sample data and expected results.
As slightwv suggested, more information would be great ;-)
In the meantime you'd probably take a look at the MERGE statement:
You'd be able to change this (not testet) snippet to suite your needs...
In the meantime you'd probably take a look at the MERGE statement:
MERGE INTO table1 e
USING (SELECT key, value FROM your_list_of_pairs_table) h
ON (e.some_id = h.some_id)
WHEN MATCHED THEN
UPDATE SET e.col2 = h.var2, e.col1 = h.var1;
You'd be able to change this (not testet) snippet to suite your needs...
ASKER
The value pairs can look like this:
and I don't expect any results other than that table1 is updated with the email addresses in column2 for all matching ReqIDs found in column1
so a table that looks like this before the update
etc.
IVer
ReqID Email
----- -----
43292 addr@company.com
39840 man@comp.co.uk
91823 woman@firm.no
etc.
and I don't expect any results other than that table1 is updated with the email addresses in column2 for all matching ReqIDs found in column1
so a table that looks like this before the update
ReqID Email Value3
----- ----- -------
43292 some
91283 thing
39840 in
91823 this
93821 column
looks like this after the update:
ReqID Email Value3
----- ----- -------
43292 addr@company.com some
91283 thing
39840 man@comp.co.uk in
91823 woman@firm.no this
93821 column
etc.
IVer
Then Alex140181's merge should do the trick -
merge into table1 t
using valuepairs v
on (t.reqid = t.reqid)
when matched then
update set t.email = v.email;
merge into table1 t
using valuepairs v
on (t.reqid = t.reqid)
when matched then
update set t.email = v.email;
sorry for the typo, meant to say on (t.reqid = v.reqid)
ASKER
Ok, sorry for being so ignorant, but the statment "using valuepairs v", how do I get my values into "valuepairs"? Is "valuepairs" a table? I am currently sitting here with all the value pairs in an Excel sheet and can copy them into a text file or as part of a script or I guess I could try to make a provisional table of them, but I'm not sure I have the rights to create new tables...
Iver
Iver
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.