如何通过 PL/SQL 中的 VARRAY 函数中的变量传递字符串值。
编码:
create or replace
PROCEDURE dynamic_query_build
(
vr_plan_sku_id IN VARCHAR2
)
IS
type plan_sku_id_array IS VARRAY(999) OF VARCHAR2(5000);
plan_sku_id plan_sku_id_array;
total integer;
vrx_plan_sku_id VARCHAR2(3000);
BEGIN
vrx_plan_sku_id:= replace(vr_plan_sku_id,',',chr(39)||','||chr(39));
vrx_plan_sku_id:=chr(39)||vrx_plan_sku_id||chr(39);
--plan_sku_id := plan_sku_id_array('Apple','Apple','Orange','Banana');
dbms_output.put_line(vrx_plan_sku_id);
plan_sku_id := plan_sku_id_array(vrx_plan_sku_id);
total := plan_sku_id.count;
dbms_output.put_line('Array count: 'total);
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END dynamic_query_build;
执行:
set serveroutput on;
declare
vr_plan_sku_id varchar2(200) := 'Apple,Apple,Orange,Banana';
BEGIN
dynamic_query_build(vr_plan_sku_id);
END;
/
我的输出:
阵列数:1
预期输出:
阵列数:4
说明: 当我传递像“plan_sku_id_array('Apple','Apple','Orange','Banana')”这样的字符串值时,我得到的计数值为4..但是当我通过变量传递相同的字符串时,它将整个值视为可变数组中的单个值。