Home » SQL & PL/SQL » SQL & PL/SQL » Query CLOB column with values in a Set List (Oracle 19.0.0.0.0 Windows 64bit)
Query CLOB column with values in a Set List [message #689972] Wed, 04 September 2024 10:28 Go to next message
Duane
Messages: 581
Registered: December 2002
Senior Member
I'm trying to figure out how to join the column of TABLE_MASTER.ID to TABLE_SET.ID_SET.  Do you use some sort of dbms_lob.substr on column ID_SET?

I've only seen one value within ID_SET but I'm assuming if multiple values are present then the values would look something like '[6,7,8,9]'.

Solution:  Join TABLE_MASTER.ID to TABLE_SET.ID_SET



CREATE TABLE TABLE_SET
(
  ID_SET  CLOB
)

insert into table_set
  (id_set)
  
  values
    ('[6]');
    
commit;


CREATE TABLE TABLE_MASTER
(
  ID  NUMBER(19) NOT NULL
)

insert into table_master
  (id)
  
  values
    (6);
    
commit;

Re: Query CLOB column with values in a Set List [message #689973 is a reply to message #689972] Wed, 04 September 2024 11:48 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3303
Registered: January 2010
Location: Connecticut, USA
Senior Member
Very bad design. You could use something like:

SELECT  *
  FROM  TABLE_SET S,
        TABLE_MASTER M
  WHERE ',' || SUBSTR(S.ID_SET,2,LENGTH(S.ID_SET) - 2) || ',' LIKE '%,' || M.ID || ',%'
/

ID_SET             ID
---------- ----------
[6]                 6

SQL>
I'd use collections:

DROP TABLE TABLE_SET PURGE
/
CREATE TABLE TABLE_SET
(
  ID_SET  SYS.ODCINUMBERLIST
)
/
insert into table_set
  (id_set)
 values
    (SYS.ODCINUMBERLIST(6));
    
commit;

SELECT  *
  FROM  TABLE_SET S,
        TABLE_MASTER M
  WHERE M.ID IN (SELECT * FROM TABLE(S.ID_SET))
/

ID_SET                       ID
-------------------- ----------
ODCINUMBERLIST(6)             6

SQL>


SY.



Re: Query CLOB column with values in a Set List [message #689974 is a reply to message #689973] Wed, 04 September 2024 11:58 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3303
Registered: January 2010
Location: Connecticut, USA
Senior Member
Oops, I completely forgot about JSON:

SELECT  *
  FROM  TABLE_SET S,
        TABLE_MASTER M
  WHERE M.ID IN (SELECT * FROM JSON_TABLE(S.ID_SET,'$[*]' COLUMNS (ID NUMBER PATH '$')))
/

ID_SET                       ID
-------------------- ----------
[6]                           6

SQL>
SY.
Re: Query CLOB column with values in a Set List [message #689975 is a reply to message #689974] Wed, 04 September 2024 12:14 Go to previous message
Duane
Messages: 581
Registered: December 2002
Senior Member
Thank you.

By the way, I just used simple table/column for this example.  The actual table/column is designed this way by the vendor.
Previous Topic: minimize the SELECT statements
Next Topic: remove comments from all_source output
Goto Forum:
  


Current Time: Sun Dec 22 00:22:06 CST 2024