Is it possible to split a word into separate lines? All the examples I found were using something to refer to as a comma or something, but I would like to separate each letter from a word, eg:
from (my table):
id | name |
---|---|
1 | banana |
to: SELECT ...
id | letter |
---|---|
1 | b |
1 | a |
1 | n |
1 | a |
1 | n |
1 | a |
3
Answers
One option is doing it with a recursive query, using the following two steps:
LEFT(RIGHT(1), n)
, which extracts the letter in position n.Recursion is halted when the nth extracting element is higher than then length of the string.
Output:
Check the demo here.
A simple way would be to join with a numbers table:
DB Fiddle
An other way more performant is by using
REGEXP_REPLACE
,json_array
andjson_table
REGEXP_REPLACE
to convert banana to b,n,a,n,ajson_array
to create a json array from b,n,a,n,ajson_table
will convert JSON data to tabular data.Demo here