我试图用类似的方式搜索一个长列,但Oracle抱怨道

问题描述 投票:3回答:2

请注意,我们使用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转换的函数,检查并返回“匹配/不匹配”结果的一些解决方案不是也很有帮助。

有人有主意吗?

oracle constraints sql-like
2个回答
1
投票

有一个函数可以将LONG转换为varchar2:

http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_sql.htm#i1025399


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

© www.soinside.com 2019 - 2024. All rights reserved.