为什么最后一个PL/SQL语句使用dbms_assert.enquote_literal失败?

RGO*_*RGO 9 oracle plsql

下面的PL/SQL块中的第一个和第二个"put_line"语句将成功,但最后一个失败.为什么?它可能是一个错误吗?

declare
  x varchar2(100);
begin
  x := 'Test'''; 
  dbms_output.put_line('x is: ' || x || ', enquoted x is: ' || dbms_assert.enquote_literal(replace(x, '''', ''''''))); 

  x := 'Te''st';
  dbms_output.put_line('x is: ' || x || ', enquoted x is: ' || dbms_assert.enquote_literal(replace(x, '''', '''''')));  

  x := '''Test';
  dbms_output.put_line('x is: ' || x || ', enquoted x is: ' || dbms_assert.enquote_literal(replace(x, '''', ''''''))); 
end;
/
Run Code Online (Sandbox Code Playgroud)

错误是:

Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.DBMS_ASSERT", line 317
ORA-06512: at "SYS.DBMS_ASSERT", line 381
ORA-06512: at line 11
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    
*Action:
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Vin*_*oor 1

无法告诉您为什么会发生这种情况,但您可以尝试如下处理:

    set serveroutput on;
declare
  x varchar2(100);
begin
  x := 'Test'''; 
  dbms_output.put_line('x is: ' || x || ', enquoted x is: ' || replace(dbms_assert.enquote_literal(replace(x, '''', '''''')), ''' ', '''')); 

  x := 'Te''st';
  dbms_output.put_line('x is: ' || x || ', enquoted x is: ' || replace(dbms_assert.enquote_literal(replace(x, '''', '''''')), ''' ', ''''));  

  x := '''Test';

  dbms_output.put_line('x is: ' || x || ', enquoted x is: ' 
  || replace(dbms_assert.enquote_literal(replace(x, '''', ' ''''')), ''' ', '''')
  ); 
end;
/

x is: Test', enquoted x is: 'Test'''
x is: Te'st, enquoted x is: 'Te''st'
x is:  'Test, enquoted x is: '''Test'
PL/SQL procedure successfully completed.
Run Code Online (Sandbox Code Playgroud)