Oracle PL/SQL 常用关键字

最近在看《Oracle PL/SQL 从入门到精通》,把看到的觉得不太熟悉的关键字记录了下来,以备查用。未完待续,后期继续增加。

constant 常量
:= 赋值
%TYPE 与数据库列相同数据类型
%ROWTYPE 与数据库行相同数据类型
declare 声明
begin...end  代码块
if...then...elsif...then...elsif...then...else...end if  分支结构
if..then..else...end if   分支结构
case virable...when...then..when...then...else...end case 分支结构
loop...if...exit...end if. end loop 循环结构
loop...exit when...end loop 循环结构
continue 跳过本次执行,进入下一次
loop...continue when...end loop 按条件跳过循环中的某一次执行
while...loop...end loop 循环结构
for i in ...loop..end loop 循环结构(计数器i不用声明)
goto 任意跳转至指定语句(存在一些约束,尽量少用)
null 不做任何操作的语句
chr(13) 回车
chr(10) 换行
loop...end loop 循环结构
&virable 此变量需要指定(手动输入)
|| 连接符

create table B as select * from A 复制表A(包含数据)
create table B as select * from A where 1 = 2 复制表A(不包含数据)
constraint 约束,用于创建表时候
check...(可使用各种逻辑运算符和函数)... 检查是否满足指定条件,创建表时候用
alter table A enable constraint_name 启用表A中的某个约束
alter table A disable constraint_name 禁用表A中的某个约束
alter table A add constraint...在表A中增加约束
alter table A drop constraint_name 在表A中删除约束
alter index old_index_name rename to new_index_name 修改索引名称
alter index index_name coalesce 合并索引
alter index index_name rebulid 重建索引

dual表   所有用户可用的实际存在的一张表,不能存储信息
rownum 一个伪列,系统给符合条件的结果添加的序列号,动态的
rowid 一个伪列,唯一标识一条记录的物理地址的ID,静态的
inner join ...on... ANSI格式内连接
x....=y....  Oracle格式内连接
table1 = table2 (+) Oracle格式左连接
table1(+) = table2  Oracle格式右连接,加号在哪边就是用哪边的数据去匹配另一个表的数据
table1 left outter join table2 ANSI格式左连接,返回table2全部数据
table1 right outter join table2 ANSI格式右连接,返回table1全部数据
table1 full outter join table2   ANSI格式全连接,返回table1  table2 全部数据
from table1,table2 Oracle格式交叉连接
table1 cross join table2 ANSI格式交叉连接
insert first/all
	when condition1 into.....
	when condition2 into.....
	else into....
subquery;                           一次插入多表

merge into  target_table 
using source_table/view/subquery
on (conditon)
when matched then update.....
when  not matched then insert....     存在就update,不存在就插入

truncate 删除整张表数据
sequence 序列,用来为数据库中的表提供一串唯一值的数字

declare 
    type type_name is record(.......);  声明记录类型,是类型,数据类型.记录是一种单行多列的数据结构

set row = .....    直接操纵整行数据,不用每一列操作
variable  table_name%rowtype 把表中一整行的数据类型直接复制过来,不用一个个列去设置
variable2 variable1%type  variable2使用与variable1相同的数据类型
variable   table_name.col_name%使用与表中某一列相同的数据类型
returning ...into table_name  返回值并写入某张表
type name1 is table of xxx index by yyyy 定义索引表(xxx,yyyy是数据类型)
type name1 as table of xxx 定义嵌套表(xxx是数据类型)
savepoint savepoint_name   定义保存点
raise  exception_name  可在一定条件下唤起也就是抛出你设定的异常
when exception_name1 or  exception_name2 then...when others then.....对于指定错误的处理
desc table_name 查看所有字段名
select * from user_tab_columns where Table_Name='用户表'; 查看所有字段



  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值