Skip to content

Commit a141f3f

Browse files
authored
Merge pull request #9986 from dahfjkg/dat/cast-decimal
Add CAST to DECIMAL with parameters to OQL docs
2 parents c16d426 + e581364 commit a141f3f

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,9 @@ The table below describes which `CAST` conversions are supported:
725725

726726
| From \ To | BOOLEAN | DATETIME | DECIMAL | INTEGER | LONG | STRING (unlimited) | STRING (limited) |
727727
|------| :------: | :------: | :------: | :------: | :------: | :------: | :------: |
728-
| BOOLEAN ||||||* |*¹ |
729-
| DATETIME ||||||* |*² |
730-
| DECIMAL |||* |* |* |* |*² |
728+
| BOOLEAN ||||||*³ |*¹ ³ |
729+
| DATETIME ||||||*³ |*² ³ |
730+
| DECIMAL |||* |* |* |* |*² |
731731
| INTEGER ||||||||
732732
| LONG ||||||||
733733
| STRING ||||||||
@@ -736,7 +736,19 @@ The table below describes which `CAST` conversions are supported:
736736

737737
²The conversion of DATETIME and DECIMAL to STRING (limited) is supported only if the value fully fits into the string length. The conversion can fail if the resulting string length is less than 20.
738738

739-
Converting `DATETIME` or `BOOLEAN` to `STRING` returns different format per database.
739+
³Converting `DATETIME` or `BOOLEAN` to `STRING` returns different format per database.
740+
741+
⁴See [`DECIMAL` precision](#dec-prec), below, for further information.
742+
743+
##### `DECIMAL` precision{#dec-prec}
744+
745+
`DECIMAL` data type can have precision and scale as parameters. This will have the following impact on the way data is converted:
746+
747+
* `DECIMAL(<precision>, <scale>)` – when both parameters are specified, those values are used as precision and scale of the resulting data type
748+
* `DECIMAL(<precision>)` – when only precision is specified, scale is set to 0. The resulting data type in that case is `DECIMAL(<precision>, 0)`
749+
* `DECIMAL` – when no parameters are specified, default values are used. Precision is set to 28, and scale is set to 8: `DECIMAL(28, 8)`
750+
751+
If the original value has more digits in the fractional part than required scale, the fractional part is rounded to the required scale. In that case, rounding is done according to the database configuration.
740752

741753
#### Examples
742754

@@ -758,6 +770,21 @@ SELECT (Number : 2) as Normal, (Cast(Number AS DECIMAL) : 2) as Casted FROM Sale
758770
| 1 | 1.0 |
759771
| 1 | 1.5 |
760772

773+
In the case of conversion to `DECIMAL`, scale and precision can be specified
774+
775+
```sql
776+
SELECT
777+
CAST('123.0987654321' AS DECIMAL) AS default_decimal,
778+
CAST('123.0987654321' AS DECIMAL(20)) AS decimal_precision,
779+
CAST('123.0987654321' AS DECIMAL(20, 6)) AS decimal_precision_scale
780+
FROM Sales.Order
781+
LIMIT 1
782+
```
783+
784+
| default_decimal | decimal_precision | decimal_precision_scale |
785+
|------:|-------:|-------:|
786+
| 123.09876543 | 123 | 123.098765 |
787+
761788
### COALESCE {#coalesce-expression}
762789

763790
Returns the value of the first `expression` that is not NULL. Can be used with columns.

0 commit comments

Comments
 (0)