oracle(cast , to_char , to_date )用法

來源:互聯網
上載者:User

標籤:

cast :

cast(要轉換的值 AS 轉換的類型)

From To BINARY_FLOAT, BINARY_DOUBLE To CHAR, VARCHAR2 To NUMBER To DATETIME, INTERVAL To NCHAR, NVARCHAR2

BINARY_FLOAT, BINARY_DOUBLE

yes

yes

yes

no

yes

CHAR, VARCHAR2

yes

yes

yes

yes

no

NUMBER

yes

yes

yes

no

yes

DATETIME, INTERVAL

no

yes

no

yes

yes

NCHAR, NVARCHAR2

yes

no

yes

no

yes

Example

CAST(‘123.4567‘ AS NUMBER(10,2)) returns the value 123.46.

通過上面的描述,我們就可以知道CAST可以將一種類型轉換為另外一種類型。

比如,將字串類型轉換為NUMBER(10,2)類型,而不僅僅是限於使用用to_number、to_char()以及to_date()類型,上述表Table 3-1代表CAST是否能夠用於該類型的相互轉換。

例子調用:

ChenZw> SELECT CAST(‘123.4567‘ AS NUMBER(10,2))  AS NUM FROM DUAL;  輸出123.46

 

to_char:    

轉換成字串類型
SELECT TO_CHAR(sysdate, ‘YYYY/MM/DD HH24:mi:ss‘) FROM DUAL

sysdate:要轉換的值 ,後面的是轉的類型(字串類型的)  

 

函數 返回 描述 例子
to_char(timestamp, text) text 把 timestamp 轉換成 string to_char(timestamp ‘now‘,‘HH12:MI:SS‘)
to_char(int, text) text 把 int4/int8 轉換成 string to_char(125, ‘999‘)
to_char(float, text) text 把 float4/float8 轉換成 string to_char(125.8, ‘999D9‘)
to_char(numeric, text) text 把 numeric 轉換成 string to_char(numeric ‘-125.8‘, ‘999D99S‘)
to_date(text, text) date 把 string 轉換成 date to_date(‘05 Dec 2000‘, ‘DD Mon YYYY‘)
to_timestamp(text, text) date 把 string 轉換成 timestamp to_timestamp(‘05 Dec 2000‘, ‘DD Mon YYYY‘)
to_number(text, text) numeric 把 string 轉換成 numeric to_number(‘12,454.8-‘, ‘99G999D9S‘)

to_date:把值轉換成日期類型的。

SELECT TO_DATE(‘2007-06-12 10:00:00‘, ‘YYYY/MM/DD HH24:mi:ss‘) FROM DUAL  --> 輸出  2007/6/12 星期二 上午 10:00:00

 

oracle(cast , to_char , to_date )用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.