本章介绍icursor()函数的多种用法。
描述:
通过索引与条件来过滤实表
语法:
T.icursor(C,…;w,I)
备注:
用索引I和条件w过滤实表T,I省略时自动找索引。结果返回单路游标。
参数:
T |
实表 |
C |
实表中的列名,缺省时读取全部列 |
w |
过滤条件,过滤条件中用到的T表字段必须跟索引中的索引字段一致 |
I |
索引名称,可省略 |
选项:
@s |
确保返回结果集对I有序且可支持大结果集,支持基于文件组的T |
@u |
从左到右处理多&&条件,缺省会根据条件优化过滤次序 |
返回值:
单路游标
示例:
|
A |
|
1 |
=file("D:\\emp1.ctx") |
|
2 |
=A1.create(#EID,NAME;EID) |
创建以EID为分段键的组表 |
3 |
=demo.cursor("select EID,NAME from employee where EID< 10") |
|
4 |
=A2.append(A3) |
|
5 |
=A2.attach(table1,DEPT,GENDER) |
在基表上增加附表 |
6 |
=demo.cursor("select EID,DEPT,GENDER from employee where EID< 10") |
|
7 |
=A5.append(A6) |
在附表中追加游标记录 |
8 |
=A7.index(test_index,GENDER=="F";DEPT;) |
创建索引test_index |
9 |
=A7.icursor(;DEPT=="HR",test_index) |
使用索引test_index查询出实表table1中DEPT为HR的所有列的数据,结果返回游标 |
10 |
=A9.fetch() |
获取游标中的数据 |
描述:
通过索引与条件来过滤集群表
语法:
T.icursor(C,…;w,I)
备注:
用索引I和条件w过滤集群表T,I省略时自动找索引。
参数:
T |
集群表 |
C |
集群表中的列名,缺省时读取全部列 |
w |
过滤条件,过滤条件中用到的T表字段必须跟索引中的索引字段一致 |
I |
索引名称,可省略 |
返回值:
集群游标
示例:
|
A |
|
1 |
=file@z("emp1.ctx","192.168.0.101:8281") |
打开集群文件 |
2 |
=A1.create() |
创建集群表 |
3 |
=A2.attach(table1) |
取出集群表table1 |
4 |
=A3.index(test_index2,GENDER=="F";DEPT;) |
创建索引文件test_index2 |
5 |
=A3.icursor(;DEPT=="HR",test_index2) |
使用索引test_index2查询出集群表A3中DEPT为HR所有列的数据,结果返回集群游标 |
6 |
=A5.fetch() |
|
7 |
=A2.index(test_index1,EID<16;NAME;) |
创建索引文件test_index1 |
8 |
=A2.icursor(EID,SURNAME;NAME=="Smith",test_index1) |
使用索引test_index1查询出集群表A2中NAME为Smith的EID,SURNAME列的数据,结果返回集群游标 |
9 |
=A8.fetch() |
|