码迷,mamicode.com
首页 > 数据库 > 详细

【转】SQL 生成连续字符

时间:2020-02-05 16:13:41      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:ascii   union   The   detail   cas   rom   tail   sdn   asc   

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 生成连续字符

标签:ascii   union   The   detail   cas   rom   tail   sdn   asc   

原文地址:https://www.cnblogs.com/com-xiaolanchong/p/12264068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!