Here’s how to use field() function.
Description:
Get the value of a specified field in a record.
Syntax:
r.field(F)
Note:
The function gets value of the Fth field in record r, or value of string parameter F. Count backward if F<0. Return null if F exceeds the boundary number of the fields or it does not exist.
Parameter:
r |
A record |
F |
The sequence number of a field, or the string parameter in which a variable can be used to reference the field name |
Return value:
The field value
Example:
|
A |
|
1 |
=demo.query("select * from EMPLOYEE")(1).field(2) |
Return the second field value of the first record in table sequence EMPLOYEE. |
2 |
=demo.query("select * from EMPLOYEE")(1).field(-2) |
Return the second-to-last field value in the first record of the table sequence EMPLOYEE. |
3 |
=demo.query("select * from EMPLOYEE")(1).field(arg1) |
arg1 is a variable. |
4 |
=demo.query("select * from EMPLOYEE")(1).field("SALARY") |
Return SALARY value in the first record of table sequelcne EMPLOYEE. |
Related functions:
Description:
Modify a value of the specified field of a record.
Syntax:
r. field(F,x)
Note:
The function modifies the value of the Fth field of record r, or the value of string parameter F, into x. Count backward if F<0. Do not execute if F exceeds the boundary number of the fields or it does not exist.
Parameter:
r |
A record |
F |
The sequence number of a field, or the string parameter in which a variable can be used to reference the field name |
x |
Expression whose computing result is the value of the Fth field, or the value of the string parameter F |
Return value:
None
Example:
|
A |
|
1 |
=demo.query("select * from EMPLOYEE") |
|
2 |
=A1(1).field(2,"Admin1") |
Change the value of the 2nd field of the record 1 to Admin1. |
3 |
=A1(1).field(-1,10000) |
Modify the value of record 1’s last field into 10,000. |
4 |
>arg1="SURNAME" |
|
5 |
=A1(1).field(arg1,"Lily") |
Modify the value of record 1’s SURNAME field into Lily. |
Related function:
Description:
Get values of a specified field of a sequence.
Syntax:
A.field(F)
Note:
The function loops through parameter A to get the value of the Fth field from each record, or the value of every string parameter F, and returns a sequence consisting of these values. Count backward if F<0. Return null if F exceeds the boundary number of the fields or it does not exist.
Parameter:
A |
A sequence |
F |
The sequence number of a field, or the string parameter in which a variable can be used to reference the field name |
Option:
@r |
When the return value is a record or record sequence, loop its members iteratively to get desired values |
Return value:
Sequence
Example:
|
A |
|
1 |
=demo.query("select * from EMPLOYEE") |
|
2 |
=A1.field(2) |
Return a sequence composed of values of the second field. |
3 |
=A1.field(-2) |
Return a sequence comprising values of the second-to-last field. |
4 |
=A1.field("NAME") |
Return a sequence composed of values of NAME field. |
5 |
>arg1="NAME" |
|
6 |
=A1.field(arg1) |
Same as A4. |
7 |
=demo.query("select * from EMPLOYEE where EID < 20") |
|
8 |
=A7.group(STATE;~.avg(SALARY):avg,~:group) |
|
9 |
=A8.field@r(3) |
After A8’s 3rd column is returned, go on to return the 3rd column of the return value.
|
Related function:
Description:
Modify the value of a specified field in a sequence.
Syntax:
A. field(F,x)
Note:
The function assigns members of sequence x sequentialy to values of Fth field in sequence A, or values of string parameter F. Count backward if F<0. Do not execute if F exceeds the boundary number of the fields or it does not exist.
Parameter:
A |
A sequence |
F |
The sequence number of a field, or the string parameter in which a variable can be used to reference the field name |
x |
A sequence whose length is equal to the number of values in Fth field, or a single value, which can be considered as a sequence in which members have the same value and their number is equal to the number of values in Fth field |
Return value:
None
Example:
|
A |
|
1 |
=demo.query("select top 3 * from EMPLOYEE") |
|
2 |
=A1.field(9,8000) |
Modify the value of the ninth field; parameter x is a single value, and it will be regarded as the sequence [8000,8000,8000]; here’s A1’s result:
|
3 |
=A1.field("SALARY",7000) |
Modify all values of SALARY field into 7000. |
4 |
>arg1="SALARY" |
|
5 |
=A1.field(arg1,7000) |
Same as A3. |
6 |
=A1.field(9,[8000,6500,9000]) |
Here parameter x is a sequence, and this is A1’s result:
|
Related function: