Cast方法oracle,Oracle的Cast的用法 -电脑资料

经常在前辈们的SQL中可以看到CAST的用法,例如:

WITH T AS(SELECT LEVEL||' ' L FROM DUAL CONNECT BY LEVEL<=5),

A(A,V) AS(SELECT CAST(L AS VARCHAR(30)),1 FROM T

UNION ALL

SELECT A||L,V+1 FROM A, T WHERE INSTR(A,L)=0 AND V<5

)

SELECT * FROM A;

例如上面的with递归语句,但是CAST因为用的比较少,今天就先给自己扫个盲了,引用Oracle的官方文档中对于CAST的描述如下:

CAST

CAST converts values from one data type to another.

Return Value

The data type specified by type_name.

Syntax

CAST(expr AS type_name)

Arguments

expr can be an expression in one of the data types.

type_name is one of the data types listed in Table1-2,"Dimensional Data Types".

Table 3-1 shows which data types can be cast into which other built-in data types. NUMBER includes NUMBER, DECIMAL, and INTEGER. DATETIME includes DATE,TIMESTAMP, TIMESTAMP WITH TIMEZONE, and TIMESTAMP WITH LOCAL TIMEZONE. INTERVAL includes INTERVAL DAY TO SECOND and INTERVAL YEAR TO MONTH.

Table 3-1 Compatible Data Types

FromTo BINARY_FLOAT, BINARY_DOUBLETo CHAR, VARCHAR2To NUMBERTo DATETIME, INTERVALTo NCHAR, NVARCHAR2

BINARY_FLOAT, BINARY_DOUBLE

yes

yes

yes

no

yes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值