首页 > 其他分享 >数据类型转换

数据类型转换

时间:2022-09-27 17:46:08浏览次数:86  
标签:类型转换 NVARCHAR2 -- data character value Oracle 数据

Implicit Data Conversion隐式数据转换

当这种转换有意义时,Oracle 数据库会自动将值从一种数据类型转换为另一种数据类型。

表 2-8是 Oracle 隐式转换的矩阵。该表显示了所有可能的转换,不考虑转换的方向或进行转换的上下文。

单元格中的“X”表示第一列和标题行中命名的数据类型的隐式转换。

DataTypeCHARVARCHAR2NCHARNVARCHAR2DATEDATETIME/INTERVALNUMBERBINARY_FLOATBINARY_DOUBLELONGRAWROWIDCLOBBLOBNCLOB

CHAR

--

X

X

X

X

X

X

X

X

X

X

X

X

X

X

VARCHAR2

X

--

X

X

X

X

X

X

X

X

X

X

X

--

X

NCHAR

X

X

--

X

X

X

X

X

X

X

X

X

X

--

X

NVARCHAR2

X

X

X

--

X

X

X

X

X

X

X

X

X

--

X

DATE

X

X

X

X

--

--

--

--

--

--

--

--

--

--

--

DATETIME/ INTERVAL

X

X

X

X

--

--

--

--

--

X

--

--

--

--

--

NUMBER

X

X

X

X

--

--

--

X

X

--

--

--

--

--

--

BINARY_FLOAT

X

X

X

X

--

--

X

--

X

--

--

--

--

--

--

BINARY_DOUBLE

X

X

X

X

--

--

X

X

--

--

--

--

--

--

--

LONG

X

X

X

X

--

XFoot 1

--

--

--

--

X

--

X

--

X

RAW

X

X

X

X

--

--

--

--

--

X

--

--

--

X

--

ROWID

X

X

X

X

--

--

--

--

--

--

--

--

--

--

--

CLOB

X

X

X

X

--

--

--

--

--

X

--

--

--

--

X

BLOB

--

--

--

--

--

--

--

--

--

--

X

--

--

--

--

NCLOB

X

X

X

X

--

--

--

--

--

X

--

--

X

--

--

不能直接将LONG转换为INTERVAL,但可以使用to_CHAR(INTERVAL)将LONG转化为VARCHAR2,然后将得到的VARCHAR2值转化为INTERVAL。

Implicit Data Type Conversion Rules

  • During INSERT and UPDATE operations, Oracle converts the value to the data type of the affected column.

  • During SELECT FROM operations, Oracle converts the data from the column to the type of the target variable.

  • When manipulating numeric values, Oracle usually adjusts precision and scale to allow for maximum capacity. In such cases, the numeric data type resulting from such operations can differ from the numeric data type found in the underlying tables.

  • When comparing a character value with a numeric value, Oracle converts the character data to a numeric value.

  • Conversions between character values or NUMBER values and floating-point number values can be inexact, because the character types and NUMBER use decimal precision to represent the numeric value, and the floating-point numbers use binary precision.

  • When converting a CLOB value into a character data type such as VARCHAR2, or converting BLOB to RAW data, if the data to be converted is larger than the target data type, then the database returns an error.

  • During conversion from a timestamp value to a DATE value, the fractional seconds portion of the timestamp value is truncated. This behavior differs from earlier releases of Oracle Database, when the fractional seconds portion of the timestamp value was rounded.

  • Conversions from BINARY_FLOAT to BINARY_DOUBLE are exact.

  • Conversions from BINARY_DOUBLE to BINARY_FLOAT are inexact if the BINARY_DOUBLE value uses more bits of precision that supported by the BINARY_FLOAT.

  • When comparing a character value with a DATE value, Oracle converts the character data to DATE.

  • When you use a SQL function or operator with an argument of a data type other than the one it accepts, Oracle converts the argument to the accepted data type.

  • When making assignments, Oracle converts the value on the right side of the equal sign (=) to the data type of the target of the assignment on the left side.

  • During concatenation operations, Oracle converts from noncharacter data types to CHAR or NCHAR.

  • During arithmetic operations on and comparisons between character and noncharacter data types, Oracle converts from any character data type to a numeric, date, or rowid, as appropriate. In arithmetic operations between CHAR/VARCHAR2 and NCHAR/NVARCHAR2, Oracle converts to a NUMBER.

  • Most SQL character functions are enabled to accept CLOBs as parameters, and Oracle performs implicit conversions between CLOB and character types. Therefore, functions that are not yet enabled for CLOBs can accept CLOBs through implicit conversion. In such cases, Oracle converts the CLOBs to CHAR or VARCHAR2 before the function is invoked. If the CLOB is larger than 4000 bytes, then Oracle converts only the first 4000 bytes to CHAR.

  • When converting RAW or LONG RAW data to or from character data, the binary data is represented in hexadecimal form, with one hexadecimal character representing every four bits of RAW data. Refer to "RAW and LONG RAW Data Types" for more information.

  • Comparisons between CHAR and VARCHAR2 and between NCHAR and NVARCHAR2 types may entail different character sets. The default direction of conversion in such cases is from the database character set to the national character set. Table 2-9 shows the direction of implicit conversions between different character types.

 

Table 2-9 Conversion Direction of Different Character Types

SourceData Typeto CHARto VARCHAR2to NCHARto NVARCHAR2

from CHAR

--

VARCHAR2

NCHAR

NVARCHAR2

from VARCHAR2

VARCHAR2

--

NVARCHAR2

NVARCHAR2

from NCHAR

NCHAR

NCHAR

--

NVARCHAR2

from NVARCHAR2

NVARCHAR2

NVARCHAR2

NVARCHAR2

--

User-defined types such as collections cannot be implicitly converted, but must be explicitly converted using CAST ... MULTISET.

标签:类型转换,NVARCHAR2,--,data,character,value,Oracle,数据
From: https://www.cnblogs.com/wonchaofan/p/16735363.html

相关文章

  • JDBC 尚硅谷 days01-数据库连接方式
    1.JDBC(JavaDatabaseConnectivitu):是一个独立于特定数据库管理系统、通用的SQL数据库存储和操作的公共接口;2.JDBC接口包括两个层次面向应用的API:JavaAPI,抽象接口,......
  • 如何实现数据库读一致性
    如何实现数据库读一致性1导读数据的一致性是数据准确的重要指标,那如何实现数据的一致性呢?本文从事务特性和事务级别的角度和大家一起学习如何实现数据的读写一致性。2......
  • 多点《基于 Databend 的 TiDB 数据归档实践》 | Data Infra 分享第 4 期总结
    本周末DataInfra社区分享中邀请到多点DMALL数据库负责人:冯光普分享了《基于Databend的TiDB数据归档实践》本次分享的主要内容:为什么选择Databend归档......
  • 数据类型
    #Java八大数据类型:(1)整数类型:byte、short、int、long(2)小数类型:float、double(3)字符类型:char(4)布尔类型:boolean##1、整数数据类型byte:1个字节,8位,256种状态,取值范围:-128,1......
  • ASEMI快恢复二极管SF3004,SF3004特性,SF3004机械数据
    编辑-ZASEMI快恢复二极管SF3004参数:型号:SF3004最大重复峰值反向电压(VRRM):400V最大RMS电桥输入电压(VRMS):280V最大直流阻断电压(VDC):400V最大平均正向整流输出电流(IF):30A峰......
  • Linux下定时自动备份Docker中所有SqlServer数据库
    准备工作一台Linux(Centos7为例)服务器。安装Docker服务。安装并启动SqlServer容器服务。编写Shell文件给出一个备份的范例#!/bin/bash#设置mssql备份目录folder......
  • 改变state里面的数据,页面没有及时渲染,需要重复触发才能渲染
    实现功能:页面首次加载,发送请求获取三条数据,每条数据里面又分为3个小数据。通过mapState映射到相应的组件上,在组件中渲染呈现上图的页面。点击查看全部,可重新发送请求,获......
  • 字节跳动数据血缘图谱升级方案设计与实现
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 数据地图平台是字节跳动内部的大数据检索平台,每天近万的字节员工在此查找所需数......
  • url跳转传数据相关
    toTodayAlarmRecord(record,site){conststartTime=dayjs(`${dayjs().format("YYYY-MM-DD")}00:00:00`).format("YYYY-MM-DDHH:mm:ss");......
  • 考察交互的方差分析与简单效应分析(附带操作数据)
    1.案例背景与分析策略1.1案例背景介绍治疗缺铁性贫血病人12例,分4组给予基础疗法和甲乙两种药物治疗,一个月后观察红细胞增加数(百万/mm),试分析甲乙用药对治疗效果的影响。......