チェック制約の内容を条件検索する方法

dba_constraints(ユーザレベルであればuser_constraints)には制約の定義が保存されているのですが、制約の内容が格納されているsearch_condition列は型がLONGなので平文で条件指定する検索ができません。

そこで How to deal with long for this query - Ask Tom にあるように、functionを定義し、これを経由することで条件指定による制約内容の検索が可能です。

以下はチェック制約(type='C')の中に<条件式>を含む定義がないかどうかの検索

setenv ORACLE_SID <SID>

sqlplus / as sysdba
set head off
set linesize 400

spool <SID>_const.csv

create or replace function get_search_condition( p_cons_name in varchar2 ) 
return varchar2
  authid current_user
  is
      l_search_condition user_constraints.search_condition%type;
  begin
      select search_condition into l_search_condition
        from user_constraints
       where constraint_name = p_cons_name;

      return l_search_condition;
  end;
  /

select owner,constraint_name,table_name,constraint_type,SEARCH_CONDITION from dba_constraints
 where owner not like 'SYS'
   and constraint_type='C'
   and STATUS='ENABLED'
   and get_search_condition(constraint_name) like '<条件式>'
;

drop function get_search_condition;

spool off
exit

便利。