informix数据库知识积累

一、嵌套查询

informix子查询:嵌套查询
(1)select first 20 * from (select first 40 * from hlrquery_log order by id desc) order by id desc无法执行
上述并不是子查询,而是隐式视图查询。
子查询应该是:
select first 20 * from tablename where col in ( select col1 from tb2 )
informix到了11版才支持隐式视图查询。informix7、8、9、10均不支持这个。
select first 40 * from hlrquery_log where id in ( select first 40 id from hlrquery_log order by id desc);在后面子查询中加了first系统也报不支持这个参数,first关键字不能用在子查询中
(2)上述查询不能执行的解决方法

①将嵌套查询的结果存入临时表,再以临时表做查询(没试验过)

select * from example_table into temp t;
select * from t;

注意,使用这种方法,必须要用创建表的权限。

②使用informix特有的嵌套查询语法

select * from table(multiset(select * from example_table));

这种方法很常用。

二、left join,right join 最后面写的where条件对xxx有效

三、informix中的某数据库temp空间不足,造成无法使用order by查询

    场景:系统中某个查询是order by查询,点击“查询”,MyEclipse报错如下:

Hibernate:……(此处是打印的SQL)
2014-11-25 09:39:56 ERROR JDBCExceptionReporter:78 - Cannot write sorted rows.
2014-11-25 09:39:56 ERROR JDBCExceptionReporter:78 - ISAM error: no free disk space for sort
2014-11-25 09:39:56 ERROR BaseAction:76 - java.lang.reflect.InvocationTargetException
……

    将打印的SQL语句放到informix数据库中执行,报错如下:

image

(低版本的仅报错:Cannot write sorted rows

    以上错误仅对数据量很大的表有,对于数据量小的表不存在该错误。经验证,以上错误和用户的电脑内存无关,是数据库内存的问题。

    select first n * from xxx order by xx;是先把表中所有数据order by,再first,所以当表数据量大时,这个查询很占内存。

    出错原因:查询的该表的数据量较大,informix中的某数据库temp空间不足,造成无法使用order by查询

    解决办法:设置该数据库,增大informix中该库的temp空间。在改例中,所查表的数据量是35万条,把改表所在库的temp内存增加到2G才可以进行带Where条件的排序查询,不带where的排序查询仍无法使用。

四、date类型

如:

select * from xxx
where xxx and current-to_date(reportTime,'%Y/%m/%d') <'365 00:00:00.000' 

其中reportTime是varchar类型

待续……

原文地址:https://www.cnblogs.com/mySummer/p/4105334.html