执行立即ora-01704字符串文字太长

时间:2017-10-20 15:22:40

标签: oracle plsql

我有以下代码

BEGIN
EXECUTE IMMEDIATE 'CALL name_package.name_procedure('string literal too long...')';
END;

当我运行它时,我收到以下错误:

ORA-01704: string literal too long
ORA-06512: line 2
01704. 00000 -  "string literal too long"
*Cause:    The string literal is longer than 4000 characters.
*Action:   Use a string literal of at most 4000 characters.
           Longer values may only be entered using bind variables.

我尝试过使用变量clob,但错误仍然存​​在,一些想法如何解决这个问题,我正在使用oracle 11g

2 个答案:

答案 0 :(得分:1)

使用绑定变量:

DECLARE
  str CLOB := EMPTY_CLOB();
BEGIN
  -- Make a long (random) string:
  FOR i IN 1 .. 10 LOOP
    str := str || DBMS_RANDOM.STRING( 'a', 4000 );
  END;

  -- Pass it into the dynamic SQL:
  EXECUTE IMMEDIATE 'CALL name_package.name_procedure( :1 )' USING str;

  -- Or just call the procedure without dynamic SQL:
  name_package.name_procedure( str );
END;

答案 1 :(得分:0)

不清楚你想要完成什么。在PL / SQL块中,您只需要引用name_package.name_procedure(' string')。假设name_procedure在name_package规范中定义。

BEGIN
    name_package.name_procedure('string');
END;

CLOB变量可以代替' string'但仅当该参数定义为CLOB而不是VARCHAR2时才会。

EXECUTE IMMEDIATE需要一个字符串。引用字符串中的引号需要呈现两次。