I create quasi-boolean columns like this:
CREATE TABLE foo
bar NUMBER(1) DEFAULT 0 NOT NULL CHECK (hide IN (0, 1))
I’m currently scraping user_tab_columns and would like to be able to determine whether a given column is a boolean or not. So far, I’ve got this:
SELECT column_name,
(SELECT COUNT(*)
FROM all_constraints
WHERE table_name = table_name
AND constraint_type = 'C'
AND REGEXP_LIKE(search_condition, '^ *' || column_name || ' +IN *\( *0, *1 *\) *$', 'i')) is_boolean
FROM user_tab_columns;
But I’m getting the following error:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Error at Line: 6 Column: 31
I’ve learned that this is because the search_condition data type is LONG, and REGEXP_LIKE() expects a character type, but I’m not sure how to resolve this issue.
Am I going about this the right way? If so, how do I fix the error I’m getting? If not, what is a better way of doing this?
You can use Oracle comments :