Oracle类型转换 [英] Oracle Type Casting

查看:87
本文介绍了Oracle类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Oracle中执行以下操作?

How can i do the following in Oracle?

SELECT  (cast field as bit) From Table

是否可以将其转换为Oracle语句 使用类似于强制转换或转换的内容?

Is there a way to conver this into an Oracle statement using something similar to cast or convert?

推荐答案

如果要查看的是如何进行二进制,十六进制,八进制转换,请参见

If what you want is to see is how to do binary,hex,oct conversions, see here. (Tom Kyte rocks)

例如

SQL> select to_bin( 123 ) bin, to_hex( 123 ) hex, to_oct( 123 ) oct from dual
2  /

BIN             HEX             OCT
--------------- --------------- ---------------
1111011         7B              173

如果您只想查看是否打开/关闭,则可以使用bitand函数(Oracle开箱即用).这里也显示了to_bin函数,但不需要使用bitand函数.

If you just wanted to see if a bit was on/off, you could use bitand function (which comes out of the box with Oracle). The to_bin function is also shown here, but not needed to use bitand function.

select to_bin(1234) bin,
  2             bitand(1234,1)+0 bit1,
  3             bitand(1234,2)+0 bit2,
  4             bitand(1234,4)+0 bit3
  5    from dual
  6  /

BIN                BIT1       BIT2       BIT3
------------ ---------- ---------- ----------
10011010010           0          2          0

您还可以使用幂函数来获取bitand(2 ^ n)的第二个参数值.例如,power(2,0),power(2,1),power(2,2)

You can also use power function to get 2nd param value for bitand (2^n). eg, power(2,0), power(2,1), power(2,2)

这篇关于Oracle类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆