This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
dev:sql:functions:extract [2010/07/27 05:18] els |
dev:sql:functions:extract [2016/06/28 22:38] (current) |
||
|---|---|---|---|
| Line 6: | Line 6: | ||
| This function returns a different datatype based on the requested field value. | This function returns a different datatype based on the requested field value. | ||
| - | |||
| ===== Syntax ===== | ===== Syntax ===== | ||
| - | EXTRACT(date_tokens FROM date_column) | + | EXTRACT(date_tokens FROM date_expression) |
| == date_tokens == | == date_tokens == | ||
| - | Required. One or more tokens representing the portions of date to be extracted, as determined by one or more of the strings shown in the table below. | + | Required. One or more tokens representing the portions of date to be extracted, as determined by one or more of the strings shown in the table below. //Date_tokens// may also contain punctuation marks to create simple format string for dates, as shown in the examples below. When punctuation marks are used, //date_tokens// should be enclosed in single quotes. |
| - | {{page>dev:appendix:date_tokens&noheader&nofooter&noeditbtn}} | + | {{page>dev:appendix:reference:date_tokens_insert&noheader&nofooter&noeditbtn}} |
| - | == date_column == | + | == date_expression == |
| - | Required. A column that is declared as a date_class datatype. The date_class datatypes are any of the date or time oriented datatypes found in the list of [[dev:appendix:datatypes|Omnidex datatypes]]. | + | Required. Any expression that returns a date-class datatype. Examples of date expressions are columns or functions that return a date-class datatype. The date_class datatypes are any of the date or time oriented datatypes found in the list of [[dev:appendix:reference:datatypes|Omnidex datatypes]]. |
| Line 39: | Line 38: | ||
| 2004-09-14 9 | 2004-09-14 9 | ||
| </code> | </code> | ||
| - | + | ==== Example 2: EXTRACT with format string ==== | |
| - | ==== Example 2: $RANDOM with a seed ==== | + | |
| <code> | <code> | ||
| - | > select $random(12345) rnd from $omnidex; | + | > select birthdate, extract ('MMM D, YYYY' from birthdate) bday from individuals; |
| - | RND | + | BIRTHDATE BDAY |
| - | ----------- | + | ------------ ------------------- |
| - | 1255939488 | + | 1938-07-14 July 14, 1938 |
| + | 1957-11-22 November 22, 1957 | ||
| + | 1960-07-28 July 28, 1960 | ||
| + | 1929-08-22 August 22, 1929 | ||
| + | 1933-07-09 July 9, 1933 | ||
| + | 1944-08-01 August 1, 1944 | ||
| + | 2004-09-14 September 14, 2004 | ||
| </code> | </code> | ||
| Line 53: | Line 57: | ||
| See also: | See also: | ||
| - | {{page>dev:sql:functions:see_also_date&noheader&nofooter&noeditbtn}} | + | {{page>dev:sql:functions:see_also_dates&noheader&nofooter&noeditbtn}} |
| - | |||
| - | {{page>:bottom_add&nofooter&noeditbtn}} | ||
| - | |||
| - | |||
| - | ### | ||
| - | |||
| - | ===== Example ===== | ||
| - | |||
| - | <code> | ||
| - | select status, | ||
| - | extract(mmm FROM orders.order_date) | ||
| - | from orders | ||
| - | where product_no='PRN4356' | ||
| - | |||
| - | ORDR JANUARY | ||
| - | ORDR DECEMBER | ||
| - | CNCL MARCH | ||
| - | </code> | ||
| {{page>:bottom_add&nofooter&noeditbtn}} | {{page>:bottom_add&nofooter&noeditbtn}} | ||