一、内部函数
  1、内部合计函数
    1)COUNT(*)          返回行数
    2)COUNT(DISTINCT COLNAME)   返回指定列中唯一值的个数
    3)SUM(COLNAME/EXPRESSION)   返回指定列或表达式的数值和;
    4)SUM(DISTINCT COLNAME)    返回指定列中唯一值的和
    5)AVG(COLNAME/EXPRESSION)   返回指定列或表达式中的数值平均值
    6)AVG(DISTINCT COLNAME)    返回指定列中唯一值的平均值
    7)MIN(COLNAME/EXPRESSION)   返回指定列或表达式中的数值最小值
    8)MAX(COLNAME/EXPRESSION)   返回指定列或表达式中的数值最大值
  2、日期与时间函数
    1)DAY(DATE/DATETIME EXPRESSION)   返回指定表达式中的当月几号
    2)MONTH(DATE/DATETIME EXPRESSION)  返回指定表达式中的月份
    3)YEAR(DATE/DATETIME EXPRESSION)   返回指定表达式中的年份
    4)WEEKDAY(DATE/DATETIME EXPRESSION) 返回指定表达式中的当周星期几
    5)DATE(NOT DATE EXPRESSION)     返回指定表达式代表的日期值
    6)TODAY                返回当前日期的日期值
    7)CURRENT[first to last]        返回当前日期的日期时间值
    8)COLNAME/EXPRESSION UNITS PRECISION  返回指定精度的指定单位数
    9)MDY(MONTH,DAY,YEAR)       返回标识指定年、月、日的日期值
    10)DATETIME(DATE/DATETIME EXPRESSION)FIRST TO LAST 返回表达式代表的日期时间值
    11)INTERVAL(DATE/DATETIME EXPRESSION)FIRST TO LAST 返回表达式代表的时间间隔值
    12)EXTEND(DATE/DATETIME EXPRESSION,[first to last])返回经过调整的日期或日期时间

    例子1、和UNITS合用,指定日期或时间单位(year,month,day,hour,minute,seond,fraction):
       let tmp_date = today + 3 UNITS day
    例子2、let tmp_date = MDY(10,30,2002)  -- 2002-10-30
    例子3、let tmp_date = today + interval(7) day to day --当前时间加上7天;
       注:该功能与1相似;
    例子4、EXTEND转换日期或日期时间值
       let tmp_inthour = extend(datetime1,hour to hour)

  3、代数函数
   1)ABS(COLNAME/EXPRESSION):       取绝对值
   2)MOD(COLNAME/EXPRESSION,DIVISOR)  返回除以除数后的模(余数)
   3)POW(COLNAME/EXPRESSION,EXPONENT)  返回一个值的指数冥
     例子:let tmp_float = pow(2,3) --8.00000000

   4)ROOT(COLNAME/EXPRESSION,[index])  返回指定列或表达式的根值

   5)SQRT(COLNAME/EXPRESSION)      返回指定列或表达式的平方根值

   6)ROUND(COLNAME/EXPRESSION,[factor]) 返回指定列或表达式的圆整化值
   7)TRUNC(COLNAME/EXPRESSION,[factor]) 返回指定列或表达式的截尾值
     说明:上两者中FACTOR指定小数位数,若不指定,则为0;若为负数,则整化到小数点左边;
     注:ROUND是在指定位上进行4舍5入;TRUNC是在指定位上直接截断;
     let tmp_float = round(4.555,2) --4.56
     let tmp_float = trunc(4.555,2) --4.55

  4、指数与对数函数
   1)EXP(COLNAME/EXPRESSION)    返回指定列或表达式的指数值
   2)LOGN(COLNAME/EXPRESSION)    返回指定列或表达式的自然对数值
   3)LOG10(COLNAME/EXPRESSION)   返回指定列或表达式的底数位10的对数值

  5、三角函数
   1)COS(RADIAN EXPRESSION)     返回指定弧度表达式的余弦值
   2)SIN(RADIAN EXPRESSION)     正弦
   3)TAN(RADIAN EXPRESSION)     正切
   4)ACOS(RADIAN EXPRESSION)     反余弦
   5)ASIN(RADIAN EXPRESSION)     反正弦
   6)ATAN(RADIAN EXPRESSION)     反正切
   7)ATAN2(X,Y)           返回坐标(X,Y)的极坐标角度组件

  6、统计函数
   1)RANGE(COLNAME)    返回指定列的最大值与最小值之差 = MAX(COLNAME)-MIN

(COLNAME)
   2)VARIANCE(COLNAME)  返回指定列的样本方差;
   3)STDEV(COLNAME)    返回指定列的标准偏差;

  7、其他函数
   1)USER              返回当前用户名
   2)HEX(COLNAME/EXPRESSION)    返回指定列或表达式的十六进制值
   3)LENGTH(COLNAME/EXPRESSION)  返回指定字符列或表达式的长度
   4)TRIM(COLNAME/EXPRESSION)   删除指定列或表达式前后的字符
   5)COLNAME/EXPRESSION || COLNAME/EXPRESSION 返回并在一起的字符;

二、IDS内部函数
  1、DBSERVERNAME   返回数据库服务器名 let tmp_char=DBSERVERNAME
  2、SITENAME     返回数据库服务器名 let tmp_char=SITENAME
   说明:两者功能相同;

  3、DBINFO(‘SPECIAL_KEYWORD')   返回只关键字值
   例子1:返回数据中每个表的DBSPACE名称
     select dbinfo('dbspace',partnum),tabname from systables
     where tabid>99 and tabtype='T' (OK)
   例子2:返回任何表中插入的最后一个SERIAL值
     select dbinfo('sqlca.sqlerrd1') from systables where tabid = 1
   例子3:返回最后一个SELECT,INSERT,UPDATE,DELETE或EXECUTE PROCEDURE语句处理的行数;
     select dbinfo('sqlca.sqlerrd2') from systables where tabid=1;

Date Manipulation

One of the more difficult concepts in Informix's handling of date
and time values concerns the use of the variables in arithmetic or
relational expressions. You can add or subtract DATE and DATETIME
variables from each other. You can add or subtract an INTERVAL to a DATE
or DATETIME. Table 1 shows the results of different types of operations
on DATE and DATETIME values.

Table 1. Operations on DATE and DATETIME Variables

First Operand

Operation

Second Operand

Result

DATE

-

DATETIME

INTERVAL

DATETIME

-

DATE

INTERVAL

DATE

+-

INTERVAL

DATETIME

DATETIME

-

DATETIME

INTERVAL

DATETIME

+-

INTERVAL

DATETIME

INTERVAL

+

DATETIME

DATETIME

INTERVAL

+-

INTERVAL

INTERVAL

DATETIME

-

CURRENT

INTERVAL

CURRENT

-

DATETIME

INTERVAL

INTERVAL

+

CURRENT

DATETIME

CURRENT

+-

INTERVAL

DATETIME

DATETIME

+-

UNITS

DATETIME

INTERVAL

+-

UNITS

INTERVAL

INTERVAL

*/

NUMBER

INTERVAL

Notice that it's always okay to subtract one DATE or DATETIME value from another, as shown here:

CURRENT - "07/01/1950" = INTERVAL (my age)
"12/25/2000" – CURRENT = INTERVAL (how long till Xmas?)

In such a case, the result is always an INTERVAL variable. It would make no sense to add two DATE or DATETIME values together. What could such an addition represent?

UNITS Keyword

When working with INTERVAL values, sometimes it is necessary to specify the precision with which you are dealing. For example, suppose you have the following field defined:

lead_time INTERVAL DAY to DAY

To add 10 days to the lead time you could use a SQL statement like this:

SELECT lead_time + INTERVAL(10) DAY to DAY
FROM orders

You could achieve the same results using the UNITS keyword:

SELECT lead_time + 10 UNITS DAY
FROM orders

Like most other programming languages, SQL often allows you to achieve the same ends with different statements. Sometimes the choice is one of personal style. Other times, one format fits in better with a structured style of code writing than another format does.

Functions

There are several built-in functions that affect date and time calculations. They can apply to either DATE or DATETIME values, with some exceptions.

TODAY

The TODAY function returns a DATE data value representing the current date. For example, you could execute a SQL function like this:

UPDATE member SET change_date = TODAY
WHER member_number = 12345

CURRENT

The CURRENT function is similar to the TODAY function, except it returns a DATETIME value. Without specific qualifiers, the default is YEAR to FRACTION(3). You can change the precision by using the same YEAR to FRACTION qualifiers as you use for DATETIMES. Thus, this would be legal:

SELECT * from member
WHERE elapsed_time < CURRENT YEAR to DAY

DATE

The DATE function takes as input a non-DATE value such as CHAR, DATETIME, or INTEGER and returns the corresponding DATE value. For example, the following SQL translates a CHARACTER value to a DATE:

SELECT * from member
WHERE enrollment_date > DATE('01/01/99')

DAY

This function returns an integer representing the day of the month. Here's an example:

SELECT * from member
WHERE DAY(enrollment_date) > DAY(CURRENT)

MONTH

This performs like the DAY function except it returns an integer between 1 and 12 representing the month:

SELECT * from member
WHERE enrollment_date > MONTH('01/01/99')

WEEKDAY

This returns an integer representing the day of the week, with 0 being Sunday and 6 being Saturday:

SELECT * from member
WHERE WEEKDAY(enrollment_date) > WEEKDAY(CURRENT)

YEAR

This function is like the ones above, only it returns a four-digit integer representing the year.

EXTEND

This function allows you to use different precisions in a DATETIME than you have specified in the declaration of the variable. It uses the same FIRST to LAST syntax as the DATETIME variables. This function is used to adjust the precision of a DATETIME variable to match the precision of an INTERVAL that you are using in a calculation. If the INTERVAL value has fields that are not part of the DATETIME value that you are using in a calculation, use the EXTEND function to adjust the precision of the DATETIME. EXTEND can either increase or decrease the precision of a DATETIME, depending upon the FIRST and LAST values.

Suppose myvariable is declared as DATETIME YEAR to DAY. If you want to add or subtract an INTERVAL defined as MINUTE, you first have to extend the DATETIME as follows:

SELECT EXTEND(myvariable, YEAR to MINUTE) –
INTERVAL(5) MINUTE to MINUTE
FROM member

The resulting value will be DATETIME YEAR to MINUTE.

MDY

The MDY function converts three-integer values into a DATE format. The first integer is the month and must evaluate to an integer in the range 1–12. The second integer is the day and must evaluate to a number in the range from 1 to however many days are in the particular month (28–31). The third expression is the year and must be a four-digit integer. Thus, the following MDY functions would each be valid:

MDY(7,1,1950)

returns a DATE of "07/01/50"

MDY(MONTH(TODAY), 1, YEAR(TODAY))

returns a DATE equal to the first day of the current month in the current year

Informix has extensive capabilities for manipulating dates and times, which can make for long and complex SQL statements. Using the three time-related data types and the time-related functions and keywords, you can accomplish almost any type of manipulation of time data. Unfortunately, getting there may be cryptic and painful. If you regularly do extensive date and time manipulation, you should understand all of the intricacies of these data structures.

Have fun!

载自 http://www.cppblog.com/wmuu/archive/2006/10/30/14381.html

Informix 常用函数的更多相关文章

  1. informix常用函数

    一.常用函数 1.decimal decimal(14,2):14位数,小数占两位:decimal(26,8),有效长度为26,小数位占8位. 2.cast cast:Oracle中的数据类型转换函数 ...

  2. oracle常用函数及示例

    学习oracle也有一段时间了,发现oracle中的函数好多,对于做后台的程序猿来说,大把大把的时间还要学习很多其他的新东西,再把这些函数也都记住是不太现实的,所以总结了一下oracle中的一些常用函 ...

  3. 总结js常用函数和常用技巧(持续更新)

    学习和工作的过程中总结的干货,包括常用函数.常用js技巧.常用正则表达式.git笔记等.为刚接触前端的童鞋们提供一个简单的查询的途径,也以此来缅怀我的前端学习之路. PS:此文档,我会持续更新. Aj ...

  4. [转]SQL 常用函数及示例

    原文地址:http://www.cnblogs.com/canyangfeixue/archive/2013/07/21/3203588.html --SQL 基础-->常用函数 --===== ...

  5. PHP常用函数、数组方法

    常用函数:rand(); 生成随机数rand(0,50); 范围随机数时间:time(); 取当前时间戳date("Y-m-d H:i:s"); Y:年 m:月份 d:天 H:当前 ...

  6. Oracle常用函数

    前一段时间学习Oracle 时做的学习笔记,整理了一下,下面是分享的Oracle常用函数的部分笔记,以后还会分享其他部分的笔记,请大家批评指正. 1.Oracle 数据库中的to_date()函数的使 ...

  7. Thinkcmf:页面常用函数

    Thinkcmf:页面常用函数 全站seo: 文章列表: {$site_seo_title}        <!--SEO标题--> {$site_seo_keywords}   < ...

  8. matlab进阶:常用功能的实现,常用函数的说明

    常用功能的实现 获取当前脚本所在目录 current_script_dir = fileparts(mfilename('fullpath')); % 结尾不带'/' 常用函数的说明 bsxfun m ...

  9. iOS导航控制器常用函数与navigationBar常用属性

    导航控制器常用函数触发时机 当视图控制器的View将要出现时触发 - (void)viewWillAppear:(BOOL)animated 当视图控制器的View已经出现时触发 - (void)vi ...

随机推荐

  1. 集合类List、Set、Map的区别、联系和遍历方式

    说集合之前,先说说数组和集合: 1.数组长度是固定的,当超过容量后会在内存中重新创建一个原来数组1.5倍长度的新数组,再把元素存进去:数组既可以存储基本数据类型,又可以存储引用数据类型. 2.集合长度 ...

  2. nginx前后端分离路由配置

    参考链接: https://blog.csdn.net/qq_30021219/article/details/80901199

  3. java 通过异常处理错误

    java的基本理念是"结构不佳的代码不能够运行" 一.概念 发现错误的理想时机是编译阶段,然而,编译期间并不能找出所有的错误,余下的问题必须在运行时期解决. 二.基本异常 异常情形 ...

  4. Java编程的逻辑 (23) - 枚举的本质

    ​本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...

  5. 在k8s集群中,利用prometheus的jmx_exporter进行tomcat的JVM性能监控,并用grafana作前端展示

    查找了很多文档,没有完全达到我要求的, 于是,作了一定的调整,成现在这样. 操作步骤如下: 一,准备好两个文件. jmx_prometheus_javaagent-0.3.1.jar jmx_expo ...

  6. Git(五)IDEA应用Git

    一.IDEA客户端git 1.提交代码到本地仓库 1. 关联Git,创建本地库 关联git 配置git环境变量 设置本地仓库目录,一般是IDEA工作空间,选择VCS->Import into V ...

  7. 镜像文件挂载及本地yum搭建

    环境:centos7.2 背景:企业内网不能上网,需安装软件以及软件之间的依赖问题 解决方案:下载和企业内网服务器相同版本的centos7.2镜像文件完整版(不是最小化的iso) 挂载镜像文件 1.上 ...

  8. 【LOJ】#2128. 「HAOI2015」数字串拆分

    题解 题中给的函数可以用矩阵快速幂递推 我们记一个数组dp[i](这个数组每个元素是一个矩阵)表示从1到i所有的数字经过拆分矩阵递推的加和 转移方法是 \(dp[i] = \sum_{j = 0}^{ ...

  9. CSS------如何让div中的div处于右下角

    如图: 代码: <div style="width:300px;height:300px"> <div style="position:absolute ...

  10. 黑马程序员_java基础笔记(14)...交通灯管理系统_编码思路及代码

    —————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流! —————————— 1,面试题——交通灯管理系统 模拟实现十字路口的交通灯管理系统逻辑,具体需求如下: ...