【问题标题】:How to get a string with more than 4000 characters as input to a Store Procedure in PLSQL?如何获取超过 4000 个字符的字符串作为 PLSQL 中存储过程的输入?
【发布时间】:2021-03-15 04:25:49
【问题描述】:
我在 oracle 中有一个存储过程,它通过 varchar2 类型的输入参数接受字符串输入,我相信 4000 字节是我们可以通过参数传递的最大长度,我需要在我的输入中有更多字符,会是什么可行的解决方案?
【问题讨论】:
标签:
oracle
stored-procedures
plsql
parameter-passing
varchar2
【解决方案1】:
一种选择是使用CLOB 数据类型。
不过,你确定你在说什么吗? 11g,传参数4000字以上没问题:
SQL> create or replace procedure p_test (par_str in varchar2)
2 is
3 l_len number;
4 begin
5 l_len := length(par_str);
6 dbms_output.put_line('length of l_len = ' || l_len);
7 end;
8 /
Procedure created.
SQL> set serveroutput on
SQL> declare
2 l_val varchar2(5000);
3 begin
4 l_val := lpad('x', 5000, 'x');
5 dbms_output.put_line('length of l_val = ' || length(l_val));
6
7 p_test(l_val);
8 end;
9 /
length of l_val = 5000
length of l_len = 5000
PL/SQL procedure successfully completed.
SQL>
【解决方案2】:
在 PL/SQL 中,varchar2 的最大长度为 32767。
您可以将上述长度的字符串传递给过程。