Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

como podemos obter o valor de VARRAY do parâmetro IN no procedimento


Eu criei um bloco anônimo com o procedimento dynamic_query_build. Adicionado o código, que dividirá a variável VARCHAR2 em varray. Acho que a chave para sua pergunta é esta linha - plan_sku_id.EXTEND();Você pode estender varray dinamicamente, mas apenas até atingir o máximo definido (no seu caso - 999) .
DECLARE
vr_plan_sku_id varchar2(200) := '5863314,5863315';
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;

position PLS_INTEGER := 0;
last_position PLS_INTEGER := 1;
tmp VARCHAR2(5000);
counter PLS_INTEGER := 1;
BEGIN
  plan_sku_id := plan_sku_id_array();
  LOOP
    position := INSTR(vr_plan_sku_id, ',', last_position);
    IF position > 0 THEN
      tmp := SUBSTR(vr_plan_sku_id, last_position, position - last_position);
      last_position := position + 1;
    ELSE
      tmp := SUBSTR(vr_plan_sku_id, last_position);
    END IF;
    plan_sku_id.EXTEND();
    plan_sku_id(counter) := tmp;
    counter := counter + 1;
    EXIT WHEN position = 0 OR counter > 10;
  END LOOP;
  total          := plan_sku_id.count;
  FOR i          IN 1 .. total
  LOOP
    dbms_output.put_line(plan_sku_id(i));
  END LOOP;
EXCEPTION
WHEN OTHERS THEN
  raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END dynamic_query_build;
BEGIN
   dynamic_query_build(vr_plan_sku_id);
END;
/