SQL/MySql

mysql concat lpad max cast right unsigned

daeyun대윤 2022. 5. 9. 11:06
SELECT CONCAT('KM-', LPAD(MAX(cast(right(a.U_ID, 7) AS UNSIGNED)+1), 7, 0)) FROM testTable AS a

 

여러 문자열를 하나의 문자열로 합치기 (CONCAT 함수)
https://extbrain.tistory.com/52

--------------------------------------------------------------------

문자열 부분 가져오기 (LEFT, MID, RIGHT)
https://extbrain.tistory.com/62

ex ) SELECT RIGHT('abcdefg', 3);
결과 : efg

--------------------------------------------------------------------

UNSIGNED 의미
https://donggu1105.tistory.com/28

컬럼값이 음수가될일이 절대없다면 쓰는게좋다

--------------------------------------------------------------------

MySQL 형변환 CAST 함수
https://ponyozzang.tistory.com/653

CAST(expr AS type)

--------------------------------------------------------------------
LPAD, RPAD (왼쪽 오른쪽에 특정 문자를 원하는 자리수만큼 넣기)
https://titis.tistory.com/105

ex ) SELECT RPAD('ABC',10,'0')  FROM DUAL;
결과 : ABC0000000
--------------------------------------------------------------------

728x90
300x250