当前位置:Gxlcms > 数据库问题 > oracle常用高级sql操作

oracle常用高级sql操作

时间:2021-07-01 10:21:17 帮助过:2人阅读

一、运算符 算术运算符:+ - * / 可以在select 语句中使用 连接运算符:||    select deptno|| dname from dept;  比较运算符:> >= = != < <= like between is null in 逻辑运算符:not and or  集合运算符: intersect ,union, union all, minus  要求:对应集合的列数和数据类型相同      查询中不能包含long 列      列的标签是第一个集合的标签      使用order by时,必须使用位置序号,不能使用列名     1. 复制表结构及其数据:   create table table_name_new as select * from table_name_old   2. 只复制表结构:   create table table_name_new as select * from table_name_old where 1=2;   或者:   create table table_name_new like table_name_old   3. 只复制表数据:   如果两个表结构一样:   insert into table_name_new select * from table_name_old   如果两个表结构不一样:   insert into table_name_new(column1,column2...) select column1,column2... from table_name_old   pasting ----------------------------------------------递归查询 --子查父(通过子节点向根节点追朔.)  查询〔特下边〕的父节点 select *   from tb_class t  start with t.class_id = ‘1030107742‘ connect by prior t.super_class_id = t.class_id order by t.tree_level desc    --父查子(通过根节点遍历子节点.)  查询〔特下边〕的子节点:结果 select *   from tb_class t  start with t.class_id = ‘1030107742‘ connect by prior t.class_id = t.super_class_id order by t.tree_level desc   1.NVL函数 NVL函数的格式如下:NVL(expr1,expr2) 含义是:如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值。   oralce 坐连接右连接   有+号的表不全部显示,对面的表全部显示。   ----------------------------------------------2016-2-24 10:06:49 2、DECODE函数 ( ) 语法:decode(expr,search1,result1, search2,result2,  …… search n,result n, default) 解释:decode函数将expr值与各search值一个一个比对,若expr值等于search值oracle数据库返回其对应的result值;若没有匹配的search值,则返回default值;若函数中default值缺省则返回null。 /*select decode(status,0,‘yes‘,1,‘no‘) as end  from sys_user  where id = 158 */   oracle高级update语句  (批量update) update t_source_phase p set p.lineno =   (select num from t_source_line l where p.lineid = l.id) where p.lineid is not null;  select的同时就update  oracle高级查询语句  (分组后按组排序)   select t.*,row_number() over(partition by planid order by sort asc ) row_number   from t_temp_pathinfo_log t   
oracle增加字段语法: @添加字段的语法:alter table tablename add (column datatype [default value][null/not null],….);     @修改字段的语法:alter table tablename modify (column datatype [default value][null/not null],….);   @删除字段的语法:alter table tablename drop (column); //2016年1月21日09:56:53 @创建序列 create sequence SEQ_DEPT minvalue 1 maxvalue 99999999 start with 241 increment by 1 cache 20;   @高级语句     1.INSERT INTO SELECT --语句         语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1         要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。         2.SELECT INTO FROM --语句         语句形式为:SELECT vale1, value2 into Table2 from Table1         要求目标表Table2不存在,因为在插入时会自动创建表Table2,并将Table1中指定字段数据复制到Table2中。示例如下:

oracle常用高级sql操作

标签:

人气教程排行