Peek - 指令碼函數
Peek() 會尋找表格中已載入或存在於內部記憶體中的列的欄位值。可以指定列號,也可以指定表格。
Syntax:
Peek(
field_name
[, row_no[, table_name ] ])
Return data type: 雙值
Arguments:
引數 | 描述 |
---|---|
field_name | 需要傳回值的欄位的名稱。輸入值必須指定為字串 (如引號中的常值)。 |
row_no |
指定所需欄位的表格中的列。可以是運算式,但是必須解析為整數。0 代表第一筆記錄,1 代表第二筆記錄,依此類推。負數表示從表格結尾算起的順序。-1 代表上次記錄讀取。 如未指定 row,則會採用 -1。 |
table_name | 沒有結束分號的表格標籤。如未指定 table_name,則會採用目前表格。若用於 LOAD 陳述式之外,或參考其他表格,則必須包括 table_name。 |
Limitations:
在內部表格的第一筆記錄中,此函數會傳回 NULL。
Example:
將範例指令碼新增至您的應用程式並予以執行。然後,至少將結果資料行中列出的欄位新增至您應用程式中的工作表以查看結果。
EmployeeDates:
Load * Inline [
EmployeeCode|StartDate|EndDate
101|02/11/2010|23/06/2012
102|01/11/2011|30/11/2013
103|02/01/2012|
104|02/01/2012|31/03/2012
105|01/04/2012|31/01/2013
106|02/11/2013|
] (delimiter is '|');
FirstEmployee:
Load EmployeeCode, Peek('EmployeeCode',0) As EmpCode
Resident EmployeeDates;
EmpCode = 101,因為 Peek('EmployeeCode',0) 傳回表格 EmployeeDates 中 EmployeeCode 的第一個值。
取代引數 row_no 的值會傳回表格中其他列的值,如下所示:
Peek('EmployeeCode',2) 傳回表格中的第三個值:103.
然而,請注意,如果未將表格指定為第三個引數 table_no,則函數會參考目前 (在此情況下,內部) 表格。 Peek('EmployeeCode',-2) 的結果是多個值:
員工代碼 | EmpCode |
---|---|
101 |
- |
102 | - |
103 | 101 |
104 | 102 |
105 | 103 |
106 | 104 |
Example:
FirstEmployee:
Load EmployeeCode, Peek('EmployeeCode',-2,'EmployeeDates') As EmpCode
Resident EmployeeDates;
By specifying the argument table_no as 'EmployeeDates', the function returns the second-to-last value of EmployeeCode in the table EmployeeDates: 105.
Example:
Peek() 函數可用於參考尚未載入的資料。
將範例指令碼新增至您的應用程式並予以執行。然後,至少將結果資料行中列出的欄位新增至您應用程式中的工作表以查看結果。
T1:
LOAD * inline [
ID|Value
1|3
1|4
1|6
3|7
3|8
2|1
2|11
5|2
5|78
5|13
] (delimiter is '|');
T2:
LOAD
*,
IF(ID=Peek('ID'), Peek('List')&','&Value,Value) AS List
RESIDENT T1
ORDER BY ID ASC;
DROP TABLE T1;
Create a table in a sheet in your app with ID, List, and Value as the dimensions.
ID | 清單 | 值 |
---|---|---|
1 | 6 | 6 |
1 | 6,3 | 3 |
1 | 6,3,4 | 4 |
2 | 11 | 11 |
2 | 11,10 | 10 |
2 | 11,10,1 | 1 |
3 | 8 | 8 |
3 | 8,7 | 7 |
5 | 13 | 13 |
5 | 13,2 | 2 |
5 | 13,2,78 | 78 |
IF() 陳述式從臨時表格 T1 建置。
Peek('ID') 會參考目前表格 T2 中先前列內的欄位 ID。
Peek('List') 會參考表格 T2 中先前列內的欄位 List,目前建置為評估運算式。
評估陳述式如下:
如果 ID 的目前值與 ID 的前一個值相同,則寫入與 Value 的目前值串連的 Peek('List') 的值。否則,僅寫入 Value 的目前值。
如果 Peek('List') 已包含串連的結果,則 Peek('List') 的新結果將串連至其中。
Example:
LOAD A, B, numsum( B, Peek( 'Bsum' ) ) as Bsum...;
在 Bsum 中建立 B 的累積。