Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
SQL iQuery Documentation - UDF and UDTF
has no ratings.
Published: 13 Jun 2019
Revised: 20 Jun 2019 - 487 days ago
Last viewed on: 19 Oct 2020 (1338 views) 
  1. SQL iQuery - RUNiQRY CL Command
  2. CSV() - Read and Parse Comma Separated Values File
  3. CSV_VAL() Extract CSV Column Value
  4. CSV_XXXX() Extract CSV Column Value as xxxx
  5. CSV_COUNT - Retrieve Field Count
  6. ObjExist - Check Object Exits
  7. DTAARA - Data Area
  8. encode_URL Encode URL for the Web
  9. encode_TAG Encode HTML TAG Content
  10. FLDLIST - List the Fields of a Table
  11. FROMHEX - Fold 2-hex Chars into 1 Char
  12. GET CPUCNT, CURLIB, ENV, SRLNBR, SYSNAME
  13. MD5_HASH - UDF - Return MD5 Hash
  14. ifsStat - Get IFS File Attributes
  15. ifsExists - Check if IFS File Exists
  16. ifsFile - Query Contents of IFS Text File
  17. ifsDIR - List IFS Directory Entires
  18. DEPFILE - List Dependent Database Relations
  19. JOB - Get Job Name Component
  20. Job_ATTR - Job Attributes
  21. JOB_DATE Retrieve the Job Date
  22. JOBLOG - Write Message to Joblog
  23. Library List UDF and Procedures
  24. MBRLIST - Member List
  25. MCHINFO Machine Type and Model Number and OS version
  26. OSVER and OSVRM Get IBM i Version/Release
  27. PrintPDF - Print a PDF to a PDF Compatible Printer
  28. CPYTOPDF - Copy SPOOLED File to PDF file
  29. OBJ_LIST List Object in a Library
  30. LIB_LIST List Descriptions of Libraries on the Library List
  31. OBJ_EXPORTS List Exported Items from an Object
  32. OBJ_STRUCT Retrieve Objects Components
  33. RTVCMDD Retrieve Command Definition
  34. RTVJOBA - Retrieve Job Attributes
  35. RTVJOBD - Retrieve Job Description
  36. RTVLASTSPLF - Retrieve ID of Last SPOOLED File for this Job
  37. RTVxxx - Retrieve Various Objects Description Table Functions
  38. WATCHLIST - List Current Watches
  39. Polymorphic Qualified Name Syntax

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

iQuery.CSV_xxxx() UDF Published by: Bob Cozzi on 13 Jun 2019 view comments

Extract CSV Value as <specific type>

The iQuery.CSV_VAL() UDF reads the CSV result set buffer and extracts and then returns the value for the column identified on the 2nd parameter. In addition, there are several other variations of this UDF to return CSV values as Text, Packed Decimal, Integer, and Date. Those functions are:

UDF Return Type Description
CSV_VAL varchar(2048) The column value is returned as a varchar value to the result set. The length will be 2k unless the user overrides that length using a CAST or similar operation. For example: (cast csv_val(data,'custname') as varchar(30))
CSV_DEC decfloat(34) The column is a packed decimal value that can be read INTO standard RPG packed decimal hoste variables.
CSV_BIGDEC dec(63,15) For larger packed decimal values, this function returns the value as a Packed Decimal with a large size.
CSV_INT integer The column is returned as an integer. Use this with values that have no decimal positions.
CSV_DATE date The column is returned as an SQL Date value.
CSV_CHAR char(2048) Same as CSV_VAL -- Alternate spelling
CSV_VARCHAR varchar(2048) Similar to CSV_VAL but has an explicit cast to VARCHAR.

For TIME and TIMESTAMP CSV content, use the CSV_VAL() UDF and then use TIMESTAMP_FORMAT() or perhaps the TIME() and TIMESTAMP() functions to convert it.

These UDFs have the same syntax, and differ only in the return value. Here is the common syntax:

Parameters

iQuery.csv_xxxx( data, 'column name' )
iQuery.csv_xxx( data, relative-column-number )

The data parameter identifies the name of the result set buffer contains the raw CSV data. This must be the column named DATA that is returend by the iQuery.CSV() UDTF. Any other value will cause unpredictable results to occur.

A column name or relative column number may be used to identify the CSV column you wish to extract. 

When a relative column number is specified, the value must be between 1 and the maximum number of CSV columns in the CSV file.

When a column name is specified, the name may be specified with or without embedded blanks. This provides more flexibility is the column naming when producing the CSV file itself. For example if the column name in the CSV file is "Customer Number" any of the following values may be speciied on the CSV_VAL UDF to identify the column by name:

  • csv_xxxx(data, 'Customer Name')
  • csv_xxxx(data, 'customername')
  • csv_xxxx(data, 'customer      NAME')

Blanks are ignored in both the CS_VAL UDF and the CSV file column headings.

Example

select csv_val(data,'custno'), csv_date(data, 'order date') from iQuery.csv('/home/pickles/customers.csv');

 

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS