cs.sortx()

Read(1140) Label: cursor, sort,

Description:

Sort data of a cursor.

Syntax:

cs.sortx(x,…;n)

Note:

The function sorts cursor cs by expression x, and returns result as a cursor. The cursor the function returns is irreversible.

Parameter:

cs

A cursor

x

An expression to sort members of cursor cs in ascending order

n

Number of buffer rows; if the number of groups reaches n, write the grouping result to a temporary file; its value will be n times of the default if it is less than 1; by default, esProc will auto-compute the value

Option:

@0

Put records with null values at the end; @0 and @n can’t work together

@n

It can only be used to make the calculation faster when the value of expression x is a positive integer over which group of records can be directly numbered. @0 and @n can’t work together

@g

Treat parameter n as the segmentation expression by which records are first segmented and then grouped and sorted

Return value:

Cursor

Example:

 

A

 

1

=demo.cursor("select NAME,BIRTHDAY,HIREDATE from Employee")

Return retrieved data as a cursor.

2

=A1.sortx(BIRTHDAY)

Sort the cursor’s BIRTHDAY field.

3

=A2.fetch()

Retrieve data from cursor A2.

4

=demo.cursor("select * from DEPT")

Return retrieved data as a cursor.

5

=A4.sortx@0(FATHER).fetch()

Sort records in the cursor by FATHER field and put the one with null value at the end.

6

=A4.sortx@g(DEPTID;FATHER==12).fetch()

Group records according to whether FATHER value is 12 and then sort each group by DEPTID.

7

=A1.sortx(BIRTHDAY;2)

Sort BIRTHDAY field in the cursor; since data is divided into two groups to be processed, write the grouping result to a temporary file.

8

=demo.cursor("select * from SCORES")

 

9

=A8.sortx@n(SCORE).fetch()

The result of fetching SCORE values are integers; here @n option is used to speed up the sorting.

Related function:

cs.fetch()

db.cursor()