Skip to content

Commit bd8feb4

Browse files
committed
Add CAST to DECIMAL with parameters to OQL docs
1 parent 0b4dade commit bd8feb4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,16 @@ The table below describes which `CAST` conversions are supported:
738738

739739
Converting `DATETIME` or `BOOLEAN` to `STRING` returns different format per database.
740740

741+
##### `DECIMAL` precision
742+
743+
`DECIMAL` data type can have precision and scale as parameters:
744+
745+
- `DECIMAL(<precision>, <scale>)` — in the case when both parameters are specified, those values are used as precision and scale of the resulting data type
746+
- `DECIMAL(<precision>)` — when only precision is specified, scaale is set to 0. The resulting data type in that case is `DECIMAL(<precision>, 0)`
747+
- `DECIMAL` — when no parameters are specified, default values are used. Precision is set to 28, and scale is set to 8: `DECIMAL(28, 8)`
748+
749+
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.
750+
741751
#### Examples
742752

743753
A frequent use case for `CAST` is to convert your date from the `DATETIME` data type to a text formatted `STRING` type:
@@ -758,6 +768,21 @@ SELECT (Number : 2) as Normal, (Cast(Number AS DECIMAL) : 2) as Casted FROM Sale
758768
| 1 | 1.0 |
759769
| 1 | 1.5 |
760770

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

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

0 commit comments

Comments
 (0)