SQL 生成连续字符

Posted 啦啦啦啦啦啦啦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL 生成连续字符相关的知识,希望对你有一定的参考价值。

WITH x AS
(SELECT 0 AS id UNION ALL
SELECT id + 1 AS id
FROM x
WHERE id < 9)
SELECT *
FROM x;

-- 生成连续字母(a-z)
WITH x AS
(SELECT 1 AS id UNION ALL
SELECT id + 1 AS id
FROM x
WHERE id < 26)
SELECT CHAR(id+96) AS id
FROM x;

-- 生成连续字符(0-9,a-z)
WITH x AS
(SELECT 0 AS id,CHAR(ascii(‘0‘)) AS cc UNION ALL
SELECT id + 1 AS id,CASE WHEN id<9 THEN CHAR(ascii(‘1‘)+id) ELSE CHAR(ascii(‘a‘)+id-9) END AS cc
FROM x
WHERE id < 35)
SELECT id, cc
FROM x;

转自:
https://blog.csdn.net/huryer/article/details/83538116

以上是关于SQL 生成连续字符的主要内容,如果未能解决你的问题,请参考以下文章

sql server 生成连续日期

如何通过SQL生成一个包含连续日期的临时表

SQL:查找给定字段连续几天具有不同字符串值的记录

某一个字段表示一天,怎么用SQL取连续三天

用SQL计算同一个字符(汉字、字母、数字、表情、符号)连续重复出现的次数

python 生成随机ASCII字符和数字的连续流。有用的快速生成随机文件。