登録されている値の最大値(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;
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme