Home > database >  Rookie to beg a SQL code
Rookie to beg a SQL code

Time:09-25

I have a table field stored data like this:
Fashion scarf
Mens plaid scarf
Cashmere scarf for men
Mens grey scarves
Mens grey scarf

I need to take out the set of field values (no repetition of words), returns a string, the result is:

Mens fashion plaid grey scarves cashmere scarf for men (word order doesn't matter)

Could you tell me how to write SQL statements to ah?

Thank you all!!!!!!

CodePudding user response:

First, then go to heavy, to merge the string
 WITH TMP AS 
(SELECT the 'fashion scarf' S
The FROM DUAL
UNION ALL
SELECT 'mens plaid scarf' S
The FROM DUAL
UNION ALL
SELECT 'cashmere scarf for men' S
The FROM DUAL
UNION ALL
SELECT 'mens grey scarves' S
The FROM DUAL
UNION ALL
SELECT 'mens grey scarf' S
The FROM DUAL)
The SELECT LISTAGG (S, ") WITHIN GROUP (ORDER BY S)
The FROM (SELECT DISTINCT REGEXP_SUBSTR (S, '[^] +' 1, LEVEL) AS S
The FROM TMP
CONNECT BY LEVEL & lt;=REGEXP_COUNT (S, '[]' + ') + 1
AND the PRIOR S=S
AND the PRIOR DBMS_RANDOM. The VALUE IS NOT NULL)
  • Related