Skip to content

Commit 78ae15a

Browse files
Damien EscaichDamien Escaich
Damien Escaich
authored and
Damien Escaich
committed
Cast clob/json to varchar
1 parent eb383f2 commit 78ae15a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,28 @@ call SQLJ.ServerControl('JAVA', 'enable', a);
5858
```
5959

6060
## Spool usage
61+
62+
63+
## Casting
64+
65+
### Cast CLOB to VARCHAR
66+
67+
If the data contains in clob is bigger than 64k (32k unicode) it cannot be cast directly to varchar.
68+
69+
First substr the first 32/64k characters then cast:
70+
71+
```sql
72+
Select cast(substr(clobfield, 1, 32000) AS VARCHAR(32000))
73+
from my_database.my_table;
74+
```
75+
76+
### Cast JSON to VARCHAR
77+
78+
Same as for CLOB except that substr does not work on JSON.
79+
80+
First cast to CLOB, substr the first 32/64k characters then cast to VARCHAR
81+
82+
```sql
83+
Select CAST(substr(cast(jsonField as CLOB), 1, 32000) AS VARCHAR(32000))
84+
from my_database.my_table;
85+
```

0 commit comments

Comments
 (0)