简体   繁体   English

如何在不使用 plsql 的情况下在 oracle 中使用带有 where 子句的插入语句

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

I want to insert like below我想像下面这样插入

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

without using PL/SQL不使用 PL/SQL

Wouldn't that be as simple as那岂不是那么简单

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

If such a student (whose values satisfy the WHERE clause) exists, a row will be inserted.如果存在这样的学生(其值满足WHERE子句),则将插入一行。 Otherwise, nothing will happen.否则,什么都不会发生。

I want direct insert statement without select我想要没有 select 的直接插入语句

The closest you will get to meeting this requirement is something like this:最接近满足此要求的是:

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

This will insert one row into STUDENT if there is at least one record in CLASS matching the given criterion.如果 CLASS 中至少有一条记录与给定条件匹配,这将在 STUDENT 中插入一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM