DAY 16
2

## 程式設計師之入門基礎必備知識(16)-SQL基礎概念(結尾)

SQL基礎也快到尾聲了，除了轉換字元形態就可以做基礎END，畢竟有實務操作一定了解的更快，以上是我自導自編，針對菜鳥入門程式設計師需要學習心態與哪些基礎技巧。
1.形態轉換
Oracle

``````select to_number('123') from dual;
``````

123;

``````select to_char(123) from dual;  >>123;
select to_date(sysdate,'yyyy/mm/dd') from dual;
``````

20130101

``````select to_char(to_number(to_char(SYSDATE,'yyyy')) - 1911,'099')||to_char(SYSDATE,'/MM/DD') from dual
``````

102/01/01

Mysql

``````select cast('123' as signed integer);
``````

123

``````select cast(123 as char(2));
``````

12 只抓取前兩，char3就是三位

2.四捨五入
Oracle

``````select round(12.39)/10 from dual;
``````

12

``````select round(12.76)/10 from dual;
``````

13

Mysql

``````select format(12.39,1);
``````

12.4

``````select format(12.76,1);
``````

12.8

3.日期時間
Oracle

``````select sysdate from dual;
``````

--日期時間

Mysql

``````select sysdate();
``````

--日期時間

4.檢查是否null
Oracle

``````select nvl(25,0) from dual;
``````

25

``````select nvl(null,0) from dual;
``````

0

Mysql

``````select ifnull(25,0);
``````

25

``````select ifnull(null,0);
``````

0

6.字串相併
--Oracle

``````select '13'||'14' from dual;
``````

1314

--Mysql

``````select concat('13','14');
``````

1314

http://ithelp.ithome.com.tw/ironman6/player/ianianwu/other/1

### 1 則留言

0

iT邦高手 1 級 ‧ 2013-10-02 13:56:32