Oracle SQL从表中获取唯一符号
我有一张表,上面有smth的说明。例如: My_Table id description ================ 1 ABC 2 ABB 3 OPAC 4 APEЧ 我需要从所有描述列中获取所有唯一的符号。 结果应该是这样的: symbol ================ A B C O P E Ч 它应该适用于所有语言,所以,正如我所看到的,正则表达式帮不上忙。Oracle SQL从表中获取唯一符号,sql,oracle,Sql,Oracle,我有一张表,上面有smth的说明。例如: My_Table id description ================ 1 ABC 2 ABB 3 OPAC 4 APEЧ 我需要从所有描述列中获取所有唯一的符号。 结果应该是这样的: symbol ================ A B C O P E Ч 它应该适用于所有语言,所以,正如我所看到的,正则表达式帮不上忙。 请帮帮我。谢谢。创建一个数字表,并用本例中所需的所有相关ID填充它1..maxlength
请帮帮我。谢谢。创建一个数字表,并用本例中所需的所有相关ID填充它1..maxlength of string
SELECT DISTINCT
locate(your_table.description, numbers.id) AS symbol
FROM
your_table
INNER JOIN
numbers
ON numbers.id >= 1
AND numbers.id <= CHAR_LENGTH(your_table.description)
或
你对所有语言都意味着什么?所有dbms?最大字符串长度是多少?结果的顺序重要吗?不,只有Oracle SQL。我的意思是,在description列中可以是任何语言的文本:英语、法语、俄语等。输入字符串可以是任何大小,输出字符串应该包含一个符号。例如,一个符号对应一条记录。顺序无关紧要。输入字符串不能有任何大小。表格本身将定义字段的最大大小。非常感谢,这正是我所需要的。纯代码答案对读者的教育作用不大。请编辑您的答案,包括一些解释。您的答案在审核队列中,因为它已被标记为低质量。
with cte (c,description_suffix) as
(
select substr(description,1,1)
,substr(description,2)
from mytable
where description is not null
union all
select substr(description_suffix,1,1)
,substr(description_suffix,2)
from cte
where description_suffix is not null
)
select c
,count(*) as cnt
from cte
group by c
order by c
with cte(n) as
(
select level
from dual
connect by level <= (select max(length(description)) from mytable)
)
select substr(t.description,c.n,1) as c
,count(*) as cnt
from mytable t
join cte c
on c.n <= length(description)
group by substr(t.description,c.n,1)
order by c
+---+-----+
| C | CNT |
+---+-----+
| A | 4 |
| B | 3 |
| C | 2 |
| E | 1 |
| O | 1 |
| P | 2 |
| Ч | 1 |
+---+-----+
SELECT DISTINCT(SUBSTR(ll,LEVEL,1)) OP --Here DISTINCT(SUBSTR(ll,LEVEL,1)) is used to get all distinct character/numeric in vertical as per requirment
FROM
(
SELECT LISTAGG(DES,'')
WITHIN GROUP (ORDER BY ID) ll
FROM My_Table --Here listagg is used to convert all values under description(des) column into a single value and there is no space in between
)
CONNECT BY LEVEL <= LENGTH(ll);