Stored Procedure to Find out Getting Different pattern for field
---------Stored procedure for Diffirent pattern finding for one column of table.
--------- input for this SP is TABLE_NAME and COLUMN_NAMEcreate or replace procedure S_PATTERN_MATCHING(my_table IN VARCHAR2, my_col IN VARCHAR2)
AUTHID CURRENT_USER IS
TYPE cur_typ IS REF CURSOR;
c cur_typ;
query_str VARCHAR2(1000);
col_value varchar2(1000);
col_count VARCHAR2(20);
Table_name varchar2(1000);
val_len number(10);
counter number(10);
counter1 number(10);
SL_NO number(10);
pattern_value varchar2(2000);
curr_pattern_value varchar2(2000);
tab_val pattern_table_list%rowtype;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
query_str := ' select ' || my_col || ' from ' || my_table || ' order by ' || my_col ;
curr_pattern_value := NULL;
counter1 := 1 ;
SL_NO := 1 ;
execute immediate ' truncate table COLUMN_PATTERN_VALUES ';
OPEN c FOR query_str ;
LOOP FETCH c INTO col_value;
EXIT WHEN c%NOTFOUND;
IF(col_value is NULL)
THEN val_len := 0;
ELSE IF (col_value is NOT NULL)
THEN val_len := length(col_value);
END IF;
END IF;
counter := 1 ;
pattern_value := '';
-----Loop for each charater in value ---------------
FOR counter in 1 .. val_len
LOOP
IF(SUBSTR(col_value,counter,1)= ' ')
Then pattern_value := pattern_value || ' ';
ELSE IF(LENGTH(TRIM(TRANSLATE(SUBSTR(col_value,counter,1),'0123456789',' '))) is NULL)
Then pattern_value := pattern_value || '9';
ELSE IF(LENGTH(TRIM(TRANSLATE(SUBSTR(col_value,counter,1), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
,' '))) is NULL)
Then pattern_value := pattern_value || 'X';
ELSE IF(LENGTH(TRIM(TRANSLATE(SUBSTR(col_value,counter,1), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
,' '))) is NOT NULL)
Then pattern_value := pattern_value || SUBSTR(col_value,counter,1);
END IF;
END IF;
END IF;
END IF;
END LOOP;
-----END Loop for each charater in value ---------------
-----inserting into COLUMN_PATTERN_VALUES table , column value and thier pattern---insert into COLUMN_PATTERN_VALUES (SL_NO,Pattern,Val)
values(SL_NO,pattern_value,col_value);
-----dbms_output.put_line(pattern_value);
-----dbms_output.put_line(col_value);
SL_NO := SL_NO+1;
END LOOP;
----- below query will create the view which shows, how many frequency of one kind of pattern we
execute immediate ' create or replace view Pattern_frequency as
select pattern, count(*) as Pattern_count from COLUMN_PATTERN_VALUES group by pattern ';
commit;
CLOSE c;
End ;
--------- input for this SP is TABLE_NAME and COLUMN_NAMEcreate or replace procedure S_PATTERN_MATCHING(my_table IN VARCHAR2, my_col IN VARCHAR2)
AUTHID CURRENT_USER IS
TYPE cur_typ IS REF CURSOR;
c cur_typ;
query_str VARCHAR2(1000);
col_value varchar2(1000);
col_count VARCHAR2(20);
Table_name varchar2(1000);
val_len number(10);
counter number(10);
counter1 number(10);
SL_NO number(10);
pattern_value varchar2(2000);
curr_pattern_value varchar2(2000);
tab_val pattern_table_list%rowtype;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
query_str := ' select ' || my_col || ' from ' || my_table || ' order by ' || my_col ;
curr_pattern_value := NULL;
counter1 := 1 ;
SL_NO := 1 ;
execute immediate ' truncate table COLUMN_PATTERN_VALUES ';
OPEN c FOR query_str ;
LOOP FETCH c INTO col_value;
EXIT WHEN c%NOTFOUND;
IF(col_value is NULL)
THEN val_len := 0;
ELSE IF (col_value is NOT NULL)
THEN val_len := length(col_value);
END IF;
END IF;
counter := 1 ;
pattern_value := '';
-----Loop for each charater in value ---------------
FOR counter in 1 .. val_len
LOOP
IF(SUBSTR(col_value,counter,1)= ' ')
Then pattern_value := pattern_value || ' ';
ELSE IF(LENGTH(TRIM(TRANSLATE(SUBSTR(col_value,counter,1),'0123456789',' '))) is NULL)
Then pattern_value := pattern_value || '9';
ELSE IF(LENGTH(TRIM(TRANSLATE(SUBSTR(col_value,counter,1), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
,' '))) is NULL)
Then pattern_value := pattern_value || 'X';
ELSE IF(LENGTH(TRIM(TRANSLATE(SUBSTR(col_value,counter,1), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
,' '))) is NOT NULL)
Then pattern_value := pattern_value || SUBSTR(col_value,counter,1);
END IF;
END IF;
END IF;
END IF;
END LOOP;
-----END Loop for each charater in value ---------------
-----inserting into COLUMN_PATTERN_VALUES table , column value and thier pattern---insert into COLUMN_PATTERN_VALUES (SL_NO,Pattern,Val)
values(SL_NO,pattern_value,col_value);
-----dbms_output.put_line(pattern_value);
-----dbms_output.put_line(col_value);
SL_NO := SL_NO+1;
END LOOP;
----- below query will create the view which shows, how many frequency of one kind of pattern we
execute immediate ' create or replace view Pattern_frequency as
select pattern, count(*) as Pattern_count from COLUMN_PATTERN_VALUES group by pattern ';
commit;
CLOSE c;
End ;
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home