oracle 中子查询的常用法
2008-11-24 13:42
239 查看
子查询:
1.使用子查询创建表
通用格式
CREATE TABLE tablename
AS
SELECT-query
eg. create table student
as
select classname,classid from class
2.使用子查询插入数据
通用格式
INSERT INTO TABLENAME[(column list)]
select columnnames from tablename where condition
eg. insert into student(classname,classid)
select classname,classid from class
3.向多张表中插入数据
通用格式(无条件)eg.
insert all
into employee_salary
values(Employeeid,lname,fname,salary,commission)
into employ_dept
values((Employeeid,lname,fname,deptid,supervision)
select Employeeid,lname,fname,salary,commission,deptid,supervision
from employee where salary>5000 or deptid<>40
通用格式(有条件).eg
insert all
when salsry >5000 then
into employee_salary
values(Employeeid,lname,fname,salary,commission)
when deptid<>40then
into employ_dept
values((Employeeid,lname,fname,deptid,supervision)
select Employeeid,lname,fname,salary,commission,deptid,supervision
from employee where salary>5000 or deptid<>40
4.有条件的insert first,
同有条件的insert all 不同的是,如果一行同时满足2个条件salary>5000和deptid<40>,则只将这条
数据插入第一张表中
5.使用子查询更新语句
通用格式
update tablename
set columnname = value or expression
where columnname operator
(select subquery)
eg.略
update tablename
set (columnname) =( select subquery)
[where condition]
eg.
update employee
set (positionid,supervisior,deptid)=
(select positionid,supervisior,deptid
from employee where employeeid =135
)
where employeeid = 200
6.获取已建序列信息
select * from user_sequences
获取序列当前值
select SEQ_BUSINESS.Currval from dual
获取序列下一个值
select SEQ_BUSINESS.NEXTVAL from dual
7.查询索引信息
select * from user_indexes
1.使用子查询创建表
通用格式
CREATE TABLE tablename
AS
SELECT-query
eg. create table student
as
select classname,classid from class
2.使用子查询插入数据
通用格式
INSERT INTO TABLENAME[(column list)]
select columnnames from tablename where condition
eg. insert into student(classname,classid)
select classname,classid from class
3.向多张表中插入数据
通用格式(无条件)eg.
insert all
into employee_salary
values(Employeeid,lname,fname,salary,commission)
into employ_dept
values((Employeeid,lname,fname,deptid,supervision)
select Employeeid,lname,fname,salary,commission,deptid,supervision
from employee where salary>5000 or deptid<>40
通用格式(有条件).eg
insert all
when salsry >5000 then
into employee_salary
values(Employeeid,lname,fname,salary,commission)
when deptid<>40then
into employ_dept
values((Employeeid,lname,fname,deptid,supervision)
select Employeeid,lname,fname,salary,commission,deptid,supervision
from employee where salary>5000 or deptid<>40
4.有条件的insert first,
同有条件的insert all 不同的是,如果一行同时满足2个条件salary>5000和deptid<40>,则只将这条
数据插入第一张表中
5.使用子查询更新语句
通用格式
update tablename
set columnname = value or expression
where columnname operator
(select subquery)
eg.略
update tablename
set (columnname) =( select subquery)
[where condition]
eg.
update employee
set (positionid,supervisior,deptid)=
(select positionid,supervisior,deptid
from employee where employeeid =135
)
where employeeid = 200
6.获取已建序列信息
select * from user_sequences
获取序列当前值
select SEQ_BUSINESS.Currval from dual
获取序列下一个值
select SEQ_BUSINESS.NEXTVAL from dual
7.查询索引信息
select * from user_indexes
相关文章推荐
- 监控oracle性能的一些常用查询
- oracle常用经典SQL查询
- Oracle 学习笔记 常用查询命令篇
- oracle中常用经典sql查询语句。
- oracle常用查询语句
- oracle数据库常用的99条查询语句
- oracle常用经典SQL查询
- ORACLE数据库常用查询二
- Oracle常用查询语句
- 常用查询集合oracle、mysql、sqlserver
- Oracle 分页和排序常用的4条查询语句
- oracle 常用SQL查询
- oracle之子查询常用
- oracle:查询用户权限常用语句
- oracle 数据库的常用查询对象
- Oracle表的常用查询实验(七)
- Oracle常用经典SQL查询(一)
- ORACLE DBA 运维常用查询
- oracle下常用查询更新命令(身份证号判断男女,更新语句多表查询)
- ORACLE常用后台表查询