开发者

How can I get values from one table to another via similar values?

开发者 https://www.devze.com 2023-01-03 17:59 出处:网络
I have a table called excel that has 3 columns,name, id, and full_name. The name part is the only one I have and I need to fill id and full_name. The other table that contains the data is called tim_p

I have a table called excel that has 3 columns, name, id, and full_name. The name part is the only one I have and I need to fill id and full_name. The other table that contains the data is called tim_pismena and has 2 columns that I need, id and pismeno_name (the actual names are not important, but i'm writing them just for clarity). In pseudooracle code :) the select that gets me the values from the second table would be done so开发者_开发问答mething like this:

SELECT tp.id, tp.pismeno_name
FROM tim_pismena tp
WHERE  upper(tp.pismeno_name) LIKE IN upper('%(SELECT name FROM excel)%')

and when used with an insert, the end result should be something like

name        id    full_name
Happy Joe   55    Very fun place Happy Joe, isn't it?


Use merge statement

  1  MERGE
  2     INTO  excel  tgt
  3     USING tim_pismenae src
  4     ON  ( upper(src.naziv_pismena) LIKE '%'||upper(tgt.ime)||'%')
  5  WHEN MATCHED
  6  THEN
  7     UPDATE
  8     SET   tgt.id = src.id
  9     ,     tgt.full_name = src.naziv_pismena
 10  WHEN NOT MATCHED
 11  THEN
 12     INSERT ( tgt.name
 13            , tgt.id
 14            , tgt.full_name )
 15     VALUES ( src.naziv_pismena
 16            , src.id
 17            , src.naziv_pismena )
 18     WHERE (1 <> 1);
0

精彩评论

暂无评论...
验证码 换一张
取 消