Oracle数据库学习(三)

6.关于null

数据库中null是一个未知数,没有任何值;进行运算时使用nvl,但是结果仍为空;在聚集函数中只有全部记录为空才会返回null。

7.insert插入

1)单行记录插入

insert into tab (f_z,f_a) values (1,to_date(‘2017-10-11’,’yyyy-mm-dd’)).

语法:语法insert into 数据表(字段名1,字段名2,……) values(字段名1的值, 字段名2的值,……)。

字段名和值要一一对应,时间日期要用单引号,非空列必须要有值对应。

(2)多行记录插入

insert into table1 (f_id, f_m, f_r) select table2.nextval as f_id, 'new user', sysdate from table1 where f_r <= to_date('2017-10-01', 'yyyy-mm-dd').

语法:insert into 数据表(字段名1,字段名2,……) (select(字段名1或运算, 字段名2或运算,……) from 数据表 where 条件)。

子查询和insert中的数据表既可以相同,也可以不同,但要求查询结果的字段和insert插入的数据表中字段属性完全一致。

8.delete

delete from tab where f_a >= 5;truncate table table1truncate是删除整个表,并且删除后不能恢复数据,但是保留数据表结构;delete删除数据可以恢复。

9.update

直接赋值更新:1)语法:update tab set f_a = new1,f_b = new2... where 条件;

              2)update tab set f_a = ‘新名称’where f_id = 2。

嵌套更新:1)语法:set 字段名1=(select 字段列表 from 数据表 where 条件),字段名2=(select 字段列表 from 数据表 where 条件),……。

          2)update table1 set table1.f_a=(select table2.f_b from table2 where table1.f_id=table2.f_id) where table1.f_id=5。

10.merge into

Merge into table1 using table2 on(table1.f_id=table2.f_id) when matched then update set table1.f_a = ‘new’ when not matched then insert(table1.f_id) values(table2.f_id)

posted @ 2018-03-29 10:34  lvanka  阅读(208)  评论(0编辑  收藏  举报