加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

oracle基础知识语法大全

发布时间:2021-01-14 07:19:50 所属栏目:站长百科 来源:网络整理
导读:ORACLE支持五种类型的完整性约束 NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值. CHECK (检查)--检查在约束中指定的条件是否得到了满足. UNIQUE (唯一)--保证在指定的列中没有重复值.在该表中每一个值

--系统异常
declare
rowD user_tbl%rowtype;
begin
select * into rowD from user_tbl;
dbms_output.put_line(rowD.id||‘‘||rowD.user_name||‘ ‘||rowD.password);
exception
when too_many_rows then
dbms_output.put_line(‘不能将多行赋予一个属性!‘);
end;
or
declare
rowD user_tbl%rowtype;
begin
select * into rowD from user_tbl where id=5;
dbms_output.put_line(rowD.id||‘ ‘||rowD.user_name||‘ ‘||rowD.password);
exception
when too_many_rows then
dbms_output.put_line(‘不能将多行赋予一个属性!‘);
when no_data_found then
dbms_output.put_line(‘没有您要查找的数据!‘);
end;

--自定义错误
declare
invalidError exception;
category varchar2(20);
begin
category:=‘&category‘;
if category not in(‘附件‘,‘顶盘‘,‘备件‘) then
raise invalidError;
else
dbms_output.put_line(‘您输入的类别是:‘||category);
end if;
exception
when invalidError then
dbms_output.put_line(‘无法识别的类别!‘);
end;

--引发应用程序异常
declare
app_exception exception;
grade user_tbl.grade%type;
begin
select grade into grade from user_tbl where id=&id;
if grade=‘A‘ then
raise app_exception;
else
dbms_output.put_line(‘查询的等级为:‘||grade);
end if;
exception
when app_exception then
raise_application_error(-20001,‘未知的等级!‘);
end;

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读