Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to 'parse' varchar2 field in SQL in Data Model for use with "IN"?

187256Apr 11 2002
A vachar2 field named "user_types" in a query in the data model has the value
"1, 12, 21, 9, 13, 10" for example.

We want to use a WHERE clause to find those user_type fields containing a 1 where 12, 10, etc. would not cause confusion with just '1'.

We tried to use the Oracle split function as follows
WHERE '1' in SPLIT(user_types, '1')
hoping to get a result interpreted as
WHERE '1' in (1, 12, 21, 9, 13, 10)
but Oracle Reports interprets the "split" as a column name.

Is it possible to use user-defined functions in a WHERE CLAUSE in SQL in Oracle Reports? We tried placing the SPLIT code into a user defined function, but Oracle Reports interpreted the user_defined function as a column name. It makes no sense to try and write our own function if SQL will not recognize it as a function.

This is the SPLIT function code:

FUNCTION SPLIT ( p_string_in IN VARCHAR2, delimiter in Varchar2:=',')
V_CHAR VARCHAR2(8000);
v_string_in Varchar2(8000);
BEGIN
v_string_in:=delimiter||p_string_in||delimiter;
For i in 1.. LENGTH(v_string_in)
LOOP v_char(i):=Substr(v_string_in,instr(v_string_in,delimiter,1,i)+1,instr(v_string_in,delimiter,1,i+1)-instr(v_string_in,delimiter,1,i)-1);
END LOOP;
RETURN v_CHAR;
END;

By the way, it would not compile unless LOOP v_char(i) was changed to LOOP v_char
so it would not have worked even if it was recognized in the SQL.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 22 2002
Added on Apr 11 2002
7 comments
325 views