oracle存储过程 md5,Oracle中的MD5(DBMS_OBFUSCATION_TOOLKIT.MD5)

Oracle PL / SQL的一个特点是存储过程参数和函数返回类型不受限制.也就是说,我们不能有这样的签名过程:

SQL> create or replace procedure my_proc (p1 in varchar2(30))

2 is

3 begin

4 null;

5 end;

6 /

Warning: Procedure created with compilation errors.

SQL> show error

Errors for PROCEDURE MY_PROC:

LINE/COL ERROR

-------- -----------------------------------------------------------------

1/34 PLS-00103: Encountered the symbol "(" when expecting one of the

following:

:= . ) , @ % default character

The symbol ":=" was substituted for "(" to continue.

SQL> create or replace procedure my_proc (p1 in varchar2)

2 is

3 begin

4 null;

5 end;

6 /

Procedure created.

SQL>

当然我们可以使用SUBTYPE定义过程的参数,但Oracle会忽略它.函数返回类型也一样……

SQL> create or replace package my_subtypes as

2 subtype ltd_string is varchar2(30);

3 end;

4 /

Package created.

SQL> create or replace function my_func return my_subtypes.ltd_string

2 is

3 begin

4 return lpad('a', 4000, 'a');

5 end;

6 /

Function created.

SQL> select length(my_func) from dual

2 /

LENGTH(MY_FUNC)

---------------

4000

SQL>

限制参数和返回类型的唯一方法是使用存储过程中的子类型声明变量.使用包中的变量,并将它们分配给OUT参数(或为函数返回变量).

这是一种冗长的说法,您可以在代码中使用DBMS_OBFUSCATION_TOOLKIT.VARCHAR2_CHECKSUM,确信它不会阻止您的函数返回32个字符.

但是,它会使查找SUBTYPE声明的开发人员感到困惑.在最糟糕的情况下,这些人将使用子类型声明他们自己的工作变量,具有以下悲剧结果:

SQL> declare

2 v my_subtypes.ltd_string;

3 begin

4 v := my_func;

5 end;

6 /

declare

*

ERROR at line 1:

ORA-06502: PL/SQL: numeric or value error: character string buffer too small

ORA-06512: at line 4

SQL>

因此,最好不要使用不合适的子类型.而是声明自己的.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值