Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Oracle constrain after search_condition's value

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!

like image 394
AdrianS Avatar asked Nov 04 '22 13:11

AdrianS


2 Answers

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....

like image 188
OTTA Avatar answered Nov 09 '22 14:11

OTTA


use

describe USER_CONSTRAINTS ;

to see that search_condition is of type LONG.

On Oracle 12 :search_condition_vc would be the solution.

like image 39
Almighty G. Avatar answered Nov 09 '22 15:11

Almighty G.