两个表ta和tb
将tb中的数据插入ta中,
insert into ta (name, sex, age, xx)
select name, sex,age ,(xx的值)
from tb
where
tb.name = ...
关于xx的值,根据tb表中的字段yy来确定,如果yy为空,xx为1, 如果yy飞空, xx为2
xx的值那一块代码应该怎么写,多谢
insert into ta (name, sex, age, xx)
select name, sex,age ,case when tb.yy is null then 1 else 2 end
from tb
where
tb.name = ...
使用Oracle自带的NVL2函数最简单
insert into ta (name, sex, age, xx)
select name, sex,age ,nvl2(yy,2,1)
from tb
where
tb.name = ...
函数说明:
nvl2(E1, E2, E3)的功能为:如果E1为NULL,则函数返回E3,若E1不为null,则返回E2。
两个表ta和tb
将tb中的数据插入ta中,
insert into ta (name, sex, age, xx)
select name, sex,age ,(xx的值)
from tb
where
tb.name = ...
关于xx的值,根据tb表中的字段yy来确定,如果yy为空,xx为1, 如果yy飞空, xx为2
xx的值 可以用 decode (yy,null,'1','2')
你可以找下decode 函数
case when then,解决这个很合适
NVL2(yy, 2, 1) NVL2(E1, E2, E3)的功能为:如果E1为NULL,则函数返回E3,若E1不为null,则返回E2。