Oracle 异常
Oracle异常分为3种:
(1)预定义异常:no_data_found等,是Oracle系统定义的异常.
declare
s_test varchar2
begin
select id into s_test from test; --此时test表无数据
exception
when no_data_found then
raise_application_error(-20001, '没有数据');
end;
(2)自定义异常:自己定义的异常,自己抛,自己捕获.
declare
exp_test exception;
begin
if 1 = 1 then
raise exp_test;
end if;
exception
when exp_test then
raise_application_error(-20002, '自定义异常');
end;
(3)非预定义异常.
--这个例子就不需要自己抛,因为已经把主键冲突的异常给覆盖了,所以只要是主键冲突,那么就是exp_test来代替以前那个了.
declare
exp_test exception;
progam exception_init(exp_test ,-1); --覆盖-1这个异常,-1代表主键冲突
begin
insert into test values('1'); --test表的主键存在1这个值.
exception
when exp_test then
raise_application_error(-20003, '主键冲突');
end;
判断参数的.
create or replace procedure addContent_test
(
s_type in varchar2,
s_count in number,
s_language in varchar2
)
is
exp_type exception;
exp_count exception;
exp_language exception;
begin
if s_type <> 50
and s_type <> 51
and s_type <> 52
and s_type <> 53
and s_type <> 54
and s_type <> 55
and s_type <> 56
and s_type <> 57
and s_type <> 0
and s_type <> 2
and s_type <> 3
and s_type <> 99999999 then
raise exp_type;
end if;
if s_count < 1 or s_count > 100 then
raise exp_count;
end if;
dbms_output.put_line(to_number(instr(s_language, ',',1,2)));
if instr(s_language, ',',1,2) > 0 then
raise exp_language;
end if;
exception
相关文档:
利用TOAD实现EXCEL数据在oracle的导入导出
1.从ORACLE数据库导出成为EXCEL文件
利用TOAD连接上数据库,访问某个表,我本机是选中表“OA_USER”
右键“Save as...”
为了解决中文乱码问题,所以选择类型为"XLS Instance",如果存在长数字型字符串被改变的问题,
请选中“String Fields as S ......
SQL中的单记录函数
1.ASCII
返回与指定的字符对应的十进制数;
SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual;
A A ZERO SPACE
--------- --------- -- ......
SQL> with tt as
2 (
3 select 'haha' string from dual union
4 select '123' from dual union
5 select 'haha12' from dual union
6 select 'haha[]' from dual union
7 select '12@@' from dual union
8 select ......
二、使用Programs
在论坛中偶尔见过有人讨论如何在ORACLE中执行操作系统命令,或是ORACLE数据库外的应用。应该说在9i及之前的版本中,虽然说并非完全无法实现(其实还是有多种方式能够变相实现的),不过复杂的实现方式让DBA使劲了力,伤透了心,费劲了事儿。
进入10g版本之后,就完全不必如此费神,因为有了DBMS ......
1.2 管理Jobs
1.2.1 启用Jobs
前面创建JOB时,由于未显式的指定ENABLED参数,因此即使指定了START_DATE,不过默认情况下JOB不会自动执行。对于这种情况,DBMS_SCHEDULER包中提供了一个过程ENABLE,可以用来修改JOB的启用状态,调用方式非常简单,例如:
SQL> exec dbms_scheduler.enable(& ......