请注意,我们使用11g,我别无选择。我正在查看all_constraints并尝试检查search_condition列,如下所示:
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';
我希望把它扔进一个快速而又脏的过程中,它会吐出一个Grails域。约束是唯一缺失的部分。是否有一种简单的方法可以排除那些只是“非空”的约束,而不是我错过的地方/喜欢?我已经尝试了显而易见的,Oracle也在将长期转换为varchar然后检查。由于我可能想要对此列进行其他操作,因此我创建一个执行kludgy PL-SQL转换的函数,检查并返回“匹配/不匹配”结果的一些解决方案不是也很有帮助。
有人有什么想法吗?
答案 0 :(得分: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
答案 1 :(得分:1)
有一个函数可以将LONG转换为varchar2:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_sql.htm#i1025399