SQL Server Stored Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajit09
    Contributor
    • Dec 2006
    • 296

    SQL Server Stored Procedure

    The below is an Oracle Stored procedure -->

    Code:
    create or replace function search_in_table(
    
                owner varchar2,
    
                table_name varchar2,
    
                search_string varchar2)
    
                return varchar2 is
    
                stmt varchar2(32700);
    
                col varchar2(32700);
    
    begin
    
                stmt := 'select ';
    
                for c in (
    
                            select column_name
    
                            from all_tab_columns
    
                            where all_tab_columns.table_name=search_in_table.table_name
    
                                        and all_tab_columns.owner=search_in_table.owner
    
                                        and data_type like '%CHAR%' )
    
                loop
    
                            stmt := stmt || 'max(case when REGEXP_LIKE("' || c.column_name ||  '", ''' || search_string || ''') then ''' || c.column_name || ' ''' || ' else null end) || ';
    
                end loop;
    
                stmt:= stmt||'nvl2(count(*),null,null) from "'||owner||'"."'||table_name||'"';
    
                execute immediate stmt into col;
    
                return col;
    
    end;

    The below Query uses the above function -->

    Code:
    select table_name,cols from (
    
                select rownum,
    
                table_name,
    
                search_in_table('SYSMAN',table_name,'[[:digit:]]') cols
    
                from all_tables where owner='SYSMAN' and tablespace_name='SYSTEM')
    
                where cols is not null;

    Please convert the function and the Query to SQL Server Stored Procedure and Query respectively.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Please find related discussion here .

    Comment

    Working...