Wednesday, September 13, 2017

Comma Separated Values Code

/* Comma Separated Values By Dynamic Sql */

DECLARE
  L_COUNT BINARY_INTEGER;
  L_ARRAY DBMS_UTILITY.LNAME_ARRAY;
  VAR VARCHAR2(100);
  temp_count9999 NUMBER;
BEGIN
  DBMS_UTILITY.COMMA_TO_TABLE (
  LIST => REGEXP_REPLACE ('10,11,121,123', '(^|,)', '\1X'), TABLEN => L_COUNT, TAB => L_ARRAY ) ;
  DBMS_OUTPUT.PUT_LINE ('L_COUNT :   ' || L_COUNT);
  FOR I IN 1 .. L_COUNT
  LOOP
    --DBMS_OUTPUT.PUT_LINE (SUBSTR (L_ARRAY (I), 2));
    VAR:=SUBSTR (L_ARRAY (I), 2);
    --DBMS_OUTPUT.PUT_LINE (VAR);
    select
    to_char(nvl(count(*), 0))  INTO temp_count9999
    from  (SELECT COLUMN_VALUE col_value FROM TABLE (gzkplib.f_string_2_tab ('10,43,51,85'))) a
    where a.col_value = VAR;
    DBMS_OUTPUT.PUT_LINE('temp_count9999 :'||temp_count9999);
  END LOOP;
END;


Dynamic Sql


If par_value is not null then

if ((PARA_VAL_TABLE IS NOT NULL) AND (PARA_VAL_COLUMN IS NOT NULL) AND (PARA_VAL_CONDITION IS NOT NULL)) THEN

--Separating With Commas **

  DBMS_UTILITY.COMMA_TO_TABLE (
  LIST => REGEXP_REPLACE (par_value, '(^|,)', '\1X'), TABLEN => L_COUNT, TAB => L_ARRAY ) ;
  DBMS_OUTPUT.PUT_LINE ('L_COUNT :   ' || L_COUNT);
  --var_value:=SUBSTR (L_ARRAY (I), 2);

FOR I IN 1 .. L_COUNT
  LOOP
  var_value:=SUBSTR (L_ARRAY (I), 2);
  temp_str:=PARA_VAL_TABLE||' where '||PARA_VAL_COLUMN || ' ' ||PARA_VAL_CONDITION  || ' ''' || var_value || '''';
    DBMS_OUTPUT.PUT_LINE (SUBSTR (L_ARRAY (I), 2));
    DBMS_OUTPUT.PUT_LINE (var_value);
    
    ValidatePara_Qry := 'select    to_char(nvl(count(*), 0)) temp_count9999  from  '||temp_str||'';
    DBMS_OUTPUT.PUT_LINE(ValidatePara_Qry);  
    EXECUTE IMMEDIATE ValidatePara_Qry into v_temp_count9999;
    DBMS_OUTPUT.PUT_LINE('temp_count9999 :'||v_temp_count9999);
   
   
     /* if #_debug
      dbms_output.put_line('Validation count = '||v_temp_count9999||' for# '||para_number||'.'||para_index||' select= '||temp_str); -- show 'Validation count = ' &temp_count9999 ' for# ' #para_number'.' #para_index  ' select= ' $temp_str
      end-if */
      if (v_temp_count9999= '0') then
      temp_str:= 'Invalid Value. Value not in ';
      temp_str:= temp_str || PARA_VAL_TABLE;
     if PARA_VAL_ERROR is null then
      SetParaError(para_number, para_index, temp_str,v_job_name ,v_job_number ) ;
      else
      SetParaError(para_number, para_index, PARA_VAL_ERROR ,v_job_name ,v_job_number ) ;
      end if;
      end if;

No comments:

Post a Comment