簡體   English   中英

如何在不使用 plsql 的情況下在 oracle 中使用帶有 where 子句的插入語句

[英]how to use insert statement with where clause from diff table in oracle without using plsql

我想像下面這樣插入

If 
   select *from class where student_name='A' ;
then
   Insert into student (Studnetname varchar2,rollno integer) values('A',1);

不使用 PL/SQL

那豈不是那么簡單

insert into student (studentname, rollno)
select student_name, rollno
from class
where student_name = 'A'
  and rollno = 1;

如果存在這樣的學生(其值滿足WHERE子句),則將插入一行。 否則,什么都不會發生。

我想要沒有 select 的直接插入語句

最接近滿足此要求的是:

Insert into student (Studnetname, rollno) 
select 'A',1
from dual 
where exists (select null from class where student_name = 'A' )
;

如果 CLASS 中至少有一條記錄與給定條件匹配,這將在 STUDENT 中插入一行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM