如何在不使用Trigger的情况下创建字母数字序列

时间:2015-10-20 15:29:46

标签: sql oracle sequence alphanumeric

序列应如下所示: -

A1
A2
A3
B1
B2
B3
C1
C2
C3

1 个答案:

答案 0 :(得分:2)

你可以使用 ROW GENERATOR 技术来实现。

SQL>  WITH data
  2       AS (SELECT Chr(65 + LEVEL - 1) str
  3           FROM   dual
  4           CONNECT BY LEVEL <= 3)
  5  SELECT str
  6         ||column_value AS alphanumeric_sequence
  7  FROM   data,
  8         TABLE(Cast(MULTISET (SELECT LEVEL
  9         FROM   dual
 10         CONNECT BY LEVEL < 3 + 1) AS sys.ODCINUMBERLIST));

ALPHANUMERIC_SEQUENCE
-----------------------------------------
A1
A2
A3
B1
B2
B3
C1
C2
C3

9 rows selected.

LEVEL 的硬编码为3,您可以根据自己的要求进行更改。该示例是根据您发布的输出。