rahcrahc 发表于 2010-04-26 11:22

请问iq如何实现表查询的底层翻页

oracle可以用rownum实现,请问iq有没有类似的方法?

xjtuhuth 发表于 2010-04-27 18:41

回复 1# rahcrahc

可以用rowid
> select STOCK_QUOTE.QUOTE_TIME, rowid(STOCK_QUOTE) from STOCK_QUOTE where rowid(STOCK_QUOTE)<20
QUOTE_TIME            rowid(STOCK_QUOTE)
--------------------------------------------
2010-02-05 12:15:59.000 1
2010-02-05 12:16:00.000 2
2010-02-05 12:16:01.000 3
2010-02-05 12:16:02.000 4
2010-02-05 12:16:03.000 5
2010-02-05 12:16:04.000 6
2010-02-05 12:16:05.000 7
2010-02-05 12:16:06.000 8
2010-02-05 12:16:07.000 9
2010-02-05 12:16:08.000 10
2010-02-05 12:16:09.000 11
2010-02-05 12:16:10.000 12
2010-02-05 12:16:11.000 13
2010-02-05 12:16:12.000 14
2010-02-05 12:16:13.000 15
2010-02-05 12:16:14.000 16
2010-02-05 12:16:15.000 17
2010-02-05 12:16:16.000 18
2010-02-05 12:16:17.000 19

(19 rows)

andkylee 发表于 2010-04-27 18:49

呵呵, asa或者iq方便点,有rowid这个强大的工具。

终于可以摆脱identity临时列了。

rahcrahc 发表于 2010-04-27 21:05

问题是,这个rowid会不会像oracle的rowid那样,属于内部值,以后随着表数据的更新和数据存储位置的变化而发生改变.另外,使用rowid查询的效率如何?

xjtuhuth 发表于 2010-04-28 08:06

回复 4# rahcrahc


    iq里的rowid和oracle里的应该不一样的

(TEST_USER)> select STOCK_QUOTE.QUOTE_TIME, rowid(STOCK_QUOTE) from STOCK_QUOTE where rowid(STOCK_QUOTE)<20
QUOTE_TIME            rowid(STOCK_QUOTE)
--------------------------------------------
2010-02-05 12:15:59.000 1
2010-02-05 12:16:00.000 2
2010-02-05 12:16:01.000 3
2010-02-05 12:16:02.000 4
2010-02-05 12:16:03.000 5
2010-02-05 12:16:04.000 6
2010-02-05 12:16:05.000 7
2010-02-05 12:16:06.000 8
2010-02-05 12:16:07.000 9
2010-02-05 12:16:08.000 10
2010-02-05 12:16:09.000 11
2010-02-05 12:16:10.000 12
2010-02-05 12:16:11.000 13
2010-02-05 12:16:12.000 14
2010-02-05 12:16:13.000 15
2010-02-05 12:16:14.000 16
2010-02-05 12:16:15.000 17
2010-02-05 12:16:16.000 18
2010-02-05 12:16:17.000 19

(19 rows)

Execution time: 0.021 seconds

(TEST_USER)> update STOCK_QUOTE set QUOTE_TIME='2010-04-05 12:15:59.000' where QUOTE_TIME='2010-02-05 12:15:59.000'
1 row(s) updated
Execution time: 0.166 seconds

(TEST_USER)> select STOCK_QUOTE.QUOTE_TIME, rowid(STOCK_QUOTE) from STOCK_QUOTE where rowid(STOCK_QUOTE)<20
QUOTE_TIME            rowid(STOCK_QUOTE)
--------------------------------------------
2010-04-05 12:15:59.000 1
2010-02-05 12:16:00.000 2
2010-02-05 12:16:01.000 3
2010-02-05 12:16:02.000 4
2010-02-05 12:16:03.000 5
2010-02-05 12:16:04.000 6
2010-02-05 12:16:05.000 7
2010-02-05 12:16:06.000 8
2010-02-05 12:16:07.000 9
2010-02-05 12:16:08.000 10
2010-02-05 12:16:09.000 11
2010-02-05 12:16:10.000 12
2010-02-05 12:16:11.000 13
2010-02-05 12:16:12.000 14
2010-02-05 12:16:13.000 15
2010-02-05 12:16:14.000 16
2010-02-05 12:16:15.000 17
2010-02-05 12:16:16.000 18
2010-02-05 12:16:17.000 19

(19 rows)

andkylee 发表于 2010-04-28 09:10

回复 5# xjtuhuth


IQ中的    rowid 和oracle中的rownum如何不一样?

感觉IQ中的rowid类似ASE中的top的效果,只是选择区间段内的数据行,不管数据如何显示的。

xjtuhuth 发表于 2010-04-28 09:21

本帖最后由 xjtuhuth 于 2010-04-28 09:34 编辑

回复 6# andkylee


    我是说iq的rowid和oracle的rowid不同,不会随着数据更新而变化,感觉和oracle的rownum类似。iq里的rowid()是sql function, 可以参考infocenter:
Sybase IQ 15.1 > Reference: Building Blocks, Tables, and Procedures > SQL Functions > Alphabetical list of functions

rahcrahc 发表于 2010-05-04 21:36

rowid对全表的查询做分页是可行的。但如果是带where条件的查询,就无能为力了,对于条件查询结果分页这种情况,各位有何高见?

andkylee 发表于 2010-05-31 17:37

本帖最后由 andkylee 于 2010-05-31 17:40 编辑

在iq15.1中有几个测试表,其中有个Contacts。
下面是简单的测试分页的例子, 实现满足条件(ID >= 20)的记录集中取第10至30个。

select number(*)as syb ,*into tempAfrom "GROUPO"."Contacts" where ID >= 20 order by ID
select * from tempA where syb>=10 and syb<=30


在iq中number(*) 类似ASE中的identity(precision) 这个函数。

类似的需求在ASE中实现方式如下:


select syb=identity(10) ,*into tempAfrom "GROUPO"."Contacts" where ID >= 20 order by ID
select * from tempA where syb>=10 and syb<=30

其中,identity(10)不是固定的, 反正是产生自增列,只要保证行数不超过数值限制就行了。 如果行数少, idenrtity(3) 也行。
页: [1]
查看完整版本: 请问iq如何实现表查询的底层翻页