close

 

 

案例來源: PTT

select col from tmp;
1
2
3
4
..
10

我要變成
00001
00002
00003
00004
....
00010

 

2種解法:

1.substr

**********

select substr('0000'||col,-5,5) from tmp;    *負號表示從右到左取直

**********

 

2.lpad 

select lpad(col,4,'000') from tmp;              *'000'字串加在欄位左邊,然後從左到右取4個值

 

 

arrow
arrow
    全站熱搜

    to52016 發表在 痞客邦 留言(0) 人氣()