我希望有一个包含客户唯一键的列,由数字+字符按升序组成。 是否有可能以某种方式指示Oracle生成许多记录,从1a到1z,然后是2a到2z等,直到300000z:
CUSTOMER_NUM
------------
10a
10b
10c
.
.
10z
11a
11b
.
到目前为止我达到的最佳状态是这样的:
select ROUND(DBMS_RANDOM.VALUE(9,21)), dbms_random.string('l', 1) from dual;
有什么想法吗?我想生成至少有300000条记录的测试表。
谢谢!
答案 0 :(得分:0)
您可能需要以下内容:
select alpha || num
from
(select substr('qwertyuiopasdfghjklzxcvbnm', level, 1) as alpha from dual connect by level <= 26)
cross join
(select level as num from dual connect by level <= 2)
order by num, alpha
第一个查询使用包含所有字符的字符串,并将其拆分为包含单个字符的26行。
第二个查询生成一定数量的数字以与字符连接。
答案 1 :(得分:0)
你可以尝试这个:
WITH n AS
(SELECT LEVEL AS Num FROM dual CONNECT BY LEVEL < 10),
c AS
(SELECT CHR(LEVEL + 96) AS alpha FROM dual CONNECT BY LEVEL <= 26)
SELECT num||alpha
FROM n
CROSS JOIN c;
答案 2 :(得分:0)
下面的查询应该会给你想要的结果。
WITH
TABLE1 AS (SELECT LEVEL PART_1 FROM DUAL CONNECT BY LEVEL <= 300000),
TABLE2 AS (SELECT CHR(LEVEL+96) AS PART_2 FROM DUAL CONNECT BY LEVEL <27)
SELECT PART_1||PART_2 AS KEY_ID FROM TABLE1,TABLE2