2012-06-28 29 views
3

只是说明一下,我们使用11g,我别无选择。我期待通过ALL_CONSTRAINTS并试图检查search_condition列,这样的事情:我试图用类似的方式搜索一个长列,但是Oracle抱怨

select * from all_constraints 
    where table_name = UPPER('STVTERM') AND 
    constraint_type = 'C' AND 
    CAST(search_condition AS VARCHAR2(100)) NOT LIKE '%IS NOT NULL'; 

我希望扔成一个快速和肮脏PROC那吐出Grails领域这一点。而限制是唯一缺失的部分。是否有一种简单的方法可以排除那些仅仅是“非空”的约束,而不是我缺少的地方?我已经尝试了这个明显的例子,Oracle在将long转换为varchar然后检查时也很尴尬。由于我可能想对此列进行其他操作,因此我创建了一个执行kludgy PL-SQL转换的函数的一些解决方案检查并返回“匹配/不匹配”结果很多帮助。

任何人有任何想法?

+0

不是真的关于grails,和(afaik)在这种情况下,“Long”意味着“long-ass-string”,不是long int。 – Sophistifunk

回答

2

这是当试图解决同样的问题,为后人的缘故,我用什么:

-- Create the decoder function 

create function funk_decode(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; 
/

-- Then use it in your select 

SELECT constraint_name, constraint_type, status, search_condition FROM USER_CONSTRAINTS where funk_decode(constraint_name) like '%SEARCH_TERM%'; 

--- Then clean up 
drop function funk_decode; 

当然,用您正在寻找的任何东西替换SEARCH_TERM。它基于我在这里找到的一些代码:http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:839298816582

相关问题