0
1

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

Posted at

登録されている値の最大値(00からZZ)を取得するSQL
SELECT
CASE
WHEN MAX(column_name) = 'ZZ' THEN 'ZZ'
WHEN REGEXP_LIKE(MAX(column_name), '[A-Z]{2}') 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
ELSE
LPAD(TO_NUMBER(MAX(column_name)) + 1, 2, '0')
END AS next_value
FROM table_name;

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?