0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Oracleで00からZZまでの連番を取得

Posted at

SELECT
CASE
WHEN MAX(column_name) = 'ZZ' THEN 'ZZ'
WHEN REGEXP_LIKE(MAX(column_name), '^[0-9]{2}$') THEN
CASE
WHEN MAX(column_name) = '99' THEN 'A1'
ELSE
CHR(ASCII(SUBSTR(MAX(column_name), 1, 1)) + 1) || '1'
END
WHEN REGEXP_LIKE(MAX(column_name), '^[A-Z][1-9]$') THEN
CASE
WHEN SUBSTR(MAX(column_name), 2, 1) = '9' THEN
SUBSTR(MAX(column_name), 1, 1) || 'A'
ELSE
SUBSTR(MAX(column_name), 1, 1) || CHR(ASCII(SUBSTR(MAX(column_name), 2, 1)) + 1)
END
WHEN MAX(column_name) = 'AZ' THEN 'B1'
END AS next_value
FROM table_name;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?