sql查询-插入
我有下面的sql脚本。当 select 查询没有找到记录时,insert 语句就不会插入任何记录。 如果选择查询没有找到记录,我希望插入一条记录,其中包含新的序列号和其他具有空值的字段。 我该怎么办呢。
insert into testing.test_ref_details(SEQNUM, TEST_TYPE,TEST_REF_NO)
select '&NEXT_SEQ_NO', '1',max(test_ref_no) as prev_test_ref1
from testing.test_runs_status
where test_type = 1
and run_status = 1
and test_end_dt = (select last_day(add_months(trunc(sysdate),-6))+2 from dual)
group by test_end_dt
;
I have the below sql script. When there is no record found by the select query there are no records inserted by the insert statement.
If no records found by select query i want to have a record inserted with the new sequence numbers and other fields with null values.
how can i do it.
insert into testing.test_ref_details(SEQNUM, TEST_TYPE,TEST_REF_NO)
select '&NEXT_SEQ_NO', '1',max(test_ref_no) as prev_test_ref1
from testing.test_runs_status
where test_type = 1
and run_status = 1
and test_end_dt = (select last_day(add_months(trunc(sysdate),-6))+2 from dual)
group by test_end_dt
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PL/SQL 解决方案:
A PL/SQL solution: