统一SQL 支持Oracle cast函数转换

该篇文章详细介绍了如何通过统一SQL将Oracle中的内建数据类型转换为PostgreSQL、TDSQL、MySQL、达梦8和LightDB等目标数据库的对应类型,提供了cast函数的具体示例和使用限制。
摘要由CSDN通过智能技术生成

统一SQL介绍

https://www.light-pg.com/docs/LTSQL/current/index.html

源和目标

源数据库:Oracle

目标数据库:Postgresql,TDSQL-MySQL,达梦8,LightDB-Oracle

操作目标


在Oracle中,cast函数允许将一种内建数据类型转换成另一种内建类型。当前统一SQL支持红框语法分支到目标数据库的转换。

在Oracle中,cast内建类型转换列表,本文针对cast(expr as number)说明经过统一SQL转换到目标库中与之适配的数据类型。

统一SQL转换

通过统一SQL到目标库Postgresql,TDSQL-MySQL,达梦8,LightDB-Oracle转换结果如下:

(关于数据类型number/decimal/dec/numeric还可参考文章:https://blog.csdn.net/Richar1/article/details/137876283 )

cast(x as target_type)测试Oracle-SQL2pg-expect2tdmysql-expect2dm-expect2ltora-expect
numberselect CAST(col_float_binary AS NUMBER) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimaldecimalnumbernumber
number(*)select CAST(col_float_binary AS NUMBER(*)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimaldecimalnumbernumber
number(*,0)select CAST(col_float_binary AS NUMBER(*,0)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38,0)decimal(38,0)number(38,0)number(38,0)
number(*,s)select CAST(col_float_binary AS NUMBER(*,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38,2)decimal(38,2)number(38,2)number(38,2)
number(4)/number(4,0)select CAST(col_float_binary AS NUMBER(4)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(4)decimal(4)number(4)number(4)
number(9)/number(9,0)select CAST(col_float_binary AS NUMBER(9)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(9)decimal(9)number(9)number(9)
number(18)/number(18,0)select CAST(col_float_binary AS NUMBER(18)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(18)decimal(18)number(18)number(18)
number(38)/number(38,0)select CAST(col_float_binary AS NUMBER(38)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38)decimal(38)number(38)number(38)
number(p,s)select CAST(col_float_binary AS NUMBER(10,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(10,2)decimal(10,2)number(10,2)number(10,2)
decimalselect CAST(col_float_binary AS decimal) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38,0)decimal(38,0)decimal(38,0)decimal(38,0)
decimal(*)select CAST(col_float_binary AS decimal(*)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38,0)decimal(38,0)decimal(38,0)decimal(38,0)
decimal(*,0)select CAST(col_float_binary AS decimal(*,0)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38,0)decimal(38,0)decimal(38,0)decimal(38,0)
decimal(*,s)select CAST(col_float_binary AS decimal(*,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38,2)decimal(38,2)decimal(38,2)decimal(38,2)
decimal(4)/decimal(4,0)select CAST(col_float_binary AS decimal(4)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(4)decimal(4)decimal(4)decimal(4)
decimal(9)/decimal(9,0)select CAST(col_float_binary AS decimal(9)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(9)decimal(9)decimal(9)decimal(9)
decimal(18)/decimal(18,0)select CAST(col_float_binary AS decimal(18)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(18)decimal(18)decimal(18)decimal(18)
decimal(38)/decimal(38,0)select CAST(col_float_binary AS decimal(38)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(38)decimal(38)decimal(38)decimal(38)
decimal(p,s)select CAST(col_float_binary AS decimal(10,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;decimal(10,2)decimal(10,2)decimal(10,2)decimal(10,2)
decselect CAST(col_float_binary AS dec) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(38,0)dec(38,0)dec(38,0)dec(38,0)
dec(*)select CAST(col_float_binary AS dec(*)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(38,0)dec(38,0)dec(38,0)dec(38,0)
dec(*,0)select CAST(col_float_binary AS dec(*,0)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(38,0)dec(38,0)dec(38,0)dec(38,0)
dec(*,s)select CAST(col_float_binary AS dec(*,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(38,2)dec(38,2)dec(38,2)dec(38,2)
dec(4)/dec(4,0)select CAST(col_float_binary AS dec(4)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(4)dec(4)dec(4)dec(4)
dec(9)/dec(9,0)select CAST(col_float_binary AS dec(9)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(9)dec(9)dec(9)dec(9)
dec(18)/dec(18,0)select CAST(col_float_binary AS dec(18)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(18)dec(18)dec(18)dec(18)
dec(38)/dec(38,0)select CAST(col_float_binary AS dec(38)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(38)dec(38)dec(38)dec(38)
dec(p,s)select CAST(col_float_binary AS dec(10,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;dec(10,2)dec(10,2)dec(10,2)dec(10,2)
numericselect CAST(col_float_binary AS numeric) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(38,0)decimal(38,0)numeric(38,0)numeric(38,0)
numeric(*)select CAST(col_float_binary AS numeric(*)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(38,0)decimal(38,0)numeric(38,0)numeric(38,0)
numeric(*,0)select CAST(col_float_binary AS numeric(*,0)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(38,0)decimal(38,0)numeric(38,0)numeric(38,0)
numeric(*,s)select CAST(col_float_binary AS numeric(*,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(38,2)decimal(38,2)numeric(38,2)numeric(38,2)
numeric(4)/numeric(4,0)select CAST(col_float_binary AS numeric(4)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(4)decimal(4)numeric(4)numeric(4)
numeric(9)/numeric(9,0)select CAST(col_float_binary AS numeric(9)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(9)decimal(9)numeric(9)numeric(9)
numeric(18)/numeric(18,0)select CAST(col_float_binary AS numeric(18)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(18)decimal(18)numeric(18)numeric(18)
numeric(38)/numeric(38,0)select CAST(col_float_binary AS numeric(38)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(38)decimal(38)numeric(38)numeric(38)
numeric(p,s)select CAST(col_float_binary AS numeric(10,2)) AS to_nu FROM topg_function_cast_table WHERE id = 1;numeric(10,2)decimal(10,2)numeric(10,2)numeric(10,2)

使用限制

可参考统一SQL官方手册中各个目标库下关于cast函数的章节

https://www.light-pg.com/docs/LTSQL/current/index.html

  • 19
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值