Query Oracle constrain after search_condition's value

房东的猫 提交于 2019-12-23 09:50:40

问题


I want to find a constraint in Oracle SQL that has a certain search_condition. Something like this:

SELECT constraint_name, constraint_type,search_condition
FROM USER_CONSTRAINTS
WHERE table_name ='MYTABLE' AND search_condition = '"myColumn" IS NOT NULL';

Problem is i get error "Ilegal use of datatype LONG".

I'd appreciate a working alternative. Thanks!


回答1:


Amend the second half of your WHERE clause as follows

SUBSTR(search_condition, 1, 21) = 'whatever you're after'

search_condition is a LONG datatype and that rather limits what you can do with it. the last parameter of the SUBSTR gives the length of the string returned so amend that as needed.

Amended as I'd forgotten the restriction on WHERE clauses, basically create a PL/SQL function to do the above and use that in your WHERE clause,

For example

FUNCTION get_long_16(pFormID NUMBER, pSectionItemID NUMBER, pSequence NUMBER)
  RETURN VARCHAR2
  AS
          l_data LONG;
  BEGIN
      SELECT far.text_answer
        INTO l_data
        FROM form_answers_repeating far
       WHERE far.form_id = pFormID
         AND far.section_item_id = pSectionItemID
         AND far.sequence = pSequence;

      RETURN SUBSTR(l_data, 1, 16);
  END;

As used here....




回答2:


use

describe USER_CONSTRAINTS ;

to see that search_condition is of type LONG.

On Oracle 12 :search_condition_vc would be the solution.




回答3:


You need to use PL/SQL apparently. See here for the example:

http://www.orafaq.com/forum/m/110779/43055/?srch=instr+long#msg_110779

Essentially you cannot use LONGs in where clauses.



来源:https://stackoverflow.com/questions/7662798/query-oracle-constrain-after-search-conditions-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!