gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:56:04 26 4
gpt4 key购买 nike

下面 PL/SQL block 中的第一个和第二个“put_line”语句将成功,但最后一个失败。为什么?会不会是一个bug?

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;
/

错误是:

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:

有什么想法吗?

最佳答案

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

    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.

关于oracle - 为什么最后一个 PL/SQL 语句使用 dbms_assert.enquote_literal 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32117879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com