## Purpose Data stored in CSV format can be interpreted as a data source using the csvtable keyword. The passing option specifies the source of the data in CSV format. The source is often the outcome of a read_file() table function or a URL download using httpget(). The interpretation process can be controlled on table level using the table options and the specification ends with the CSV columns being mapped to data source columns using their relative position within a row. ```sql select t.* from (select 'a;1;2' || chr(13) || chr(10) || 'b;3;4' csvfragment ) x join csvtable ( passing x.csvfragment columns text_column varchar2 position 1 , next_column varchar2 position 2 , a_number number position 3 ) t ``` ## Syntax ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart TD csvTableSpec_start((START)) csvTableSpec_start --> csvTableSpec_0_0["CSVTABLE("]:::quoted csvTableSpec_0_0 --> csvTableSpec_0_2[csvTablePassing] csvTableSpec_0_2 --> csvTableSpec_0_3[csvTableLiteral] csvTableSpec_0_3 --> csvTableSpec_0_4[csvTableOptions] csvTableSpec_0_4 --> csvTableSpec_0_5[csvTableColumns] csvTableSpec_0_5 --> csvTableSpec_0_6[")"]:::quoted csvTableSpec_0_6 --> csvTableSpec_end((END)) ``` ## csvTableOptions ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart TD csvTableOptions_start((START)) csvTableOptions_start --> csvTableOptions_0_0[ROW]:::quoted csvTableOptions_0_0 --> csvTableOptions_0_1[DELIMITER]:::quoted csvTableOptions_0_1 --> csvTableOptions_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>] csvTableOptions_0_2 --> csvTableOptions_0_3[COLUMN]:::quoted csvTableOptions_0_3 --> csvTableOptions_0_4[DELIMITER]:::quoted csvTableOptions_0_4 --> csvTableOptions_0_5[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>] csvTableOptions_0_5 --> csvTableOptions_0_6[SKIP_]:::quoted csvTableOptions_0_6 --> csvTableOptions_0_7[LINES]:::quoted csvTableOptions_0_7 --> csvTableOptions_0_8[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>] csvTableOptions_0_8 --> csvTableOptions_end((END)) ``` ## Purpose The interpretation process can be controlled on table level using the table options. The row delimiter is a text that separates two CSV rows, such as "chr(13) || chr(10)" or simply a pipe character "'|'". The default is the operating system-specific variant of new line. The column delimiter is a text that separates two CSV columns such as "';'". The default is comma. Data in CSV will typically have one or more header CSV rows labeling the individual columns. The 'skip lines' statement excludes the first number of CSV rows from processing. ## csvTableLiteral ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart LR csvTableLiteral_start((START)) csvTableLiteral_start --> csvTableLiteral_0_0[LITERAL]:::quoted csvTableLiteral_0_0 --> csvTableLiteral_0_1[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>] csvTableLiteral_0_1 --> csvTableLiteral_end((END)) ``` ## Purpose A literal value containing a valid CSV document. ## csvTablePassing ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart LR Start((START)) --> csvTablePassing csvTablePassing -->| | passingSourceOrPathExpression passingSourceOrPathExpression --> End((END)) ``` ## csvTableColumns ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart TD csvTableColumns_start((START)) csvTableColumns_start --> csvTableColumns_0_0[COLUMNS]:::quoted csvTableColumns_0_0 --> csvTableColumns_0_1[csvTableColumnSpec] csvTableColumns_0_1 --> csvTableColumns_0_2[","]:::quoted csvTableColumns_0_2 --> csvTableColumns_0_3[csvTableColumnSpec] csvTableColumns_0_3 --> csvTableColumns_end((END)) ``` ## Purpose A list of CSV table column specifications. ## csvTableColumnSpec ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart TD csvTableColumnSpec_start((START)) csvTableColumnSpec_start --> csvTableColumnSpec_0_0[identifier] csvTableColumnSpec_0_0 --> csvTableColumnSpec_0_1[sqlDataTypeExtended] csvTableColumnSpec_0_1 --> csvTableColumnSpec_0_2[FORMAT]:::quoted csvTableColumnSpec_0_2 --> csvTableColumnSpec_0_3[stringConstant] csvTableColumnSpec_0_3 --> csvTableColumnSpec_0_4[POSITION]:::quoted csvTableColumnSpec_0_4 --> csvTableColumnSpec_0_5[numericConstant] csvTableColumnSpec_0_5 --> csvTableColumnSpec_0_6[NEXT]:::quoted csvTableColumnSpec_0_6 --> csvTableColumnSpec_end((END)) ``` ## Purpose Each CSV column is mapped to a data source column using it's relative position within the CSV row. Position 1 represents the first CSV column. A position can be represented using an integer, or by specifying the keyword 'NEXT'. The keyword 'NEXT' specifies that the column is located one position higher than the previous column. When there is no previous column, the column is located at position 1.