How to 'parse' varchar2 field in SQL in Data Model for use with "IN"?
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.