当前位置:网站首页>Chapter III data type (II)
Chapter III data type (II)
2022-06-10 18:55:00 【yaoxin521123】
List of articles
The third chapter data type ( Two )
SQL System data type mapping
In the above table is DDL and IRIS The syntax of the data type expression is SQL.SystemDataTypes Default mapping for configuration . For the system data type and user data type provided , A separate mapping table is available .
To view and modify the current data type mapping , Please go to the administration portal , Choose system management 、 To configure 、SQL And object settings 、 System DDL mapping .
understand DDL Data type mapping
Change the data type from DDL Mapping to IRIS when , General parameters and function parameters follow the following rules :
- Conventional parameters - These in DDL Data types and IRIS The data type is marked with
%#Format logo . for example :
VARCHAR(%1)
Mapping to :
%String(MAXLEN=%1)
therefore ,DDL The data type is :
VARCHAR(10)
Mapping to :
%String(MAXLEN=10)
- Function parameter — When DDL The parameters in the data type must undergo some conversion before they can be put into IRIS When the data type is , Use these parameters . An example of this would be DDL The numeric precision and scale parameters of the data type are converted to IRIS Data type
MAXVAL、MINVALandSCALEParameters . for example :
DECIMAL(%1,%2)
Mapping to :
%Numeric(MAXVAL=<|'$$maxval^%apiSQL(%1,%2)'|>,
MINVAL=<|'$$minval^%apiSQL(%1,%2)'|>,
SCALE=%2)
DDL data type DECIMAL Using parameters Precision (%1) and Scale (%2), but IRIS data type %Numeric No precision parameters . therefore , To put DECIMAL Convert to %Numeric, Must be Precision The parameter is converted to the appropriate %Numeric Parameters , under these circumstances , By way of IRIS Function format 、maxval and minval be applied to DECIMAL Provided parameters . special <|'xxx'|> grammar ( As shown above ) instructions DDL The processor performs parameter replacement , Then call the function with the supplied value . <|'xxx'|> The expression is then replaced by the value returned by the function call .
Consider this example with actual values , There may be an accuracy of 4 position 、 The number of decimal places is 2 Of DECIMAL data type :
DECIMAL(4,2)
Mapping to :
%Numeric(MAXVAL=<|'$$maxval^%apiSQL(4,2)'|>,
MINVAL=<|'$$minval^%apiSQL(4,2)'|>,
SCALE=2)
The calculation for the :
%Numeric(MAXVAL=99.99,MINVAL=-99.99,SCALE=2)
- Additional parameters —— Data type classes can be defined and cannot be used DDL Additional data definition parameters for data type definitions . These include data validation operations , For example, an enumerated list of allowed data values 、 Allowed data value pattern matching and exceeding
MAXLENAutomatic truncation of maximum length data value .
Data type priority
When an operation can return multiple different values , And these values may have different data types ,IRIS Assign the return value to the data type with the highest priority . for example ,NUMERIC The data type can contain all possible INTEGER Data type value , but INTEGER The data type cannot contain all possible NUMERIC Data type value . therefore NUMERIC Higher priority ( More inclusive ).
for example , If CASE Statement has a data type of INTEGER Possible result values for , And a data type of NUMERIC Possible result values for , No matter which of the two cases is adopted , The actual result is always NUMERIC type .
The priority of data types is as follows , From the highest ( Including the most ) To the lowest :
LONGVARBINARY
LONGVARCHAR
VARBINARY
VARCHAR
GUID
TIMESTAMP
DOUBLE
NUMERIC
BIGINT
INTEGER
DATE
TIME
SMALLINT
TINYINT
BIT
Normalization and verification
%Library.DataType Superclasses contain classes of specific data types . These data type classes provide Normalize() Method to normalize the input value to a data type format , And provide IsValid() Method to determine whether the input value is valid for the data type , And various mode conversion methods , for example LogicalToDisplay( ) and DisplayToLogical().
The following example shows %TimeStamp Data type Normalize() Method :
/// d ##class(PHA.TEST.SQLFunction).NormalizeValidate()
ClassMethod NormalizeValidate()
{
s indate = 64701
s tsdate = ##class(%Library.TimeStamp).Normalize(indate)
w "%TimeStamp date: ",tsdate
}
DHC-APP>d ##class(PHA.TEST.SQLFunction).NormalizeValidate()
%TimeStamp date: 2018-02-22 00:00:00
/// d ##class(PHA.TEST.SQLFunction).NormalizeValidate2()
ClassMethod NormalizeValidate2()
{
s indate = "2018-2-22"
s tsdate = ##class(%Library.TimeStamp).Normalize(indate)
w "%TimeStamp date: ",tsdate
}
DHC-APP> d ##class(PHA.TEST.SQLFunction).NormalizeValidate2()
%TimeStamp date: 2018-02-22 00:00:00
The following example shows %TimeStamp Data type IsValid() Method :
/// d ##class(PHA.TEST.SQLFunction).NormalizeValidate3()
ClassMethod NormalizeValidate3()
{
s datestr = "July 4, 2018"
s stat = ##class(%Library.TimeStamp).IsValid(datestr)
if stat = 1 {
w datestr," is a valid %TimeStamp",!
} else {
w datestr," is not a valid %TimeStamp",!
}
}
DHC-APP> d ##class(PHA.TEST.SQLFunction).NormalizeValidate3()
July 4, 2018 is not a valid %TimeStamp
/// d ##class(PHA.TEST.SQLFunction).NormalizeValidate4()
ClassMethod NormalizeValidate4()
{
s leapdate = "2016-02-29 00:00:00"
s noleap = "2018-02-29 00:00:00"
s stat = ##class(%Library.TimeStamp).IsValid(leapdate)
if stat = 1 {
w leapdate," is a valid %TimeStamp",!
} else {
w leapdate," is not a valid %TimeStamp",!
}
s stat = ##class(%Library.TimeStamp).IsValid(noleap)
if stat = 1 {
w noleap," is a valid %TimeStamp",!
} else {
w noleap," is not a valid %TimeStamp",!
}
}
DHC-APP> d ##class(PHA.TEST.SQLFunction).NormalizeValidate4()
2016-02-29 00:00:00 is a valid %TimeStamp
2018-02-29 00:00:00 is not a valid %TimeStamp
边栏推荐
- 第二章 数据类型(一)
- 数字化时代,企业为什么要做数字化转型?
- Adobe Premiere基礎-工具使用(選擇工具,剃刀工具,等常用工具)(三)
- Adobe Premiere Foundation (track related) (V)
- && 与 ||
- Adobe Premiere foundation - material nesting (animation of Tiktok ending avatar) (IX)
- Rewrite clear Bayesian formula with base ratio
- Db2 SQL PL的动态SQL
- muduo源码剖析——以三个切片浅析muduo库代码设计的严谨性、高效性与灵活性
- How can bi help enterprises reduce labor, time and management costs?
猜你喜欢

Uniapp native JS to convert the Gregorian calendar to the lunar calendar

Opencv does not rely on any third-party database for face detection

5. golang generics and reflection

Data URL

Adobe Premiere foundation - opacity (mixed mode) (XII)

Huawei cloud Kunpeng devkit code migration practice

数字化时代,企业为什么要做数字化转型?

华为云鲲鹏DevKit代码迁移实战

瑞芯微RK1126平台 平台移植libevent 交叉编译libevent

Adobe Premiere foundation - Import and export, merge materials, source file compilation, offline (II)
随机推荐
Anchor type and row data type of DB2 SQL pl
[代码]神经符号生成机器
商业智能BI的服务对象,企业管理者的管理“欲望”该如何实现?
Adobe Premiere基础(动画制作)(七)
Db2 SQL PL的锚点类型和行数据类型
企业数据质量管理:如何进行数据质量评估?
Adobe Premiere基础-工具使用(选择工具,剃刀工具,等常用工具)(三)
The value of Bi in the enterprise: business analysis and development decision
Three ways generated by stream lambda
Seata安装Window环境
[kuangbin] topic 22 interval DP
第三章 数据类型(二)
Adobe Premiere Foundation (animation) (VII)
Adobe Premiere foundation - opacity (matte) (11)
Rewrite clear Bayesian formula with base ratio
基于谱加权的波束方向图分析
阵列信号处理仿真之四——Z变换分析阵列多项式
华为云鲲鹏DevKit代码迁移实战
Metadata management, the basic construction of enterprises in the digital era
SQL 函数