Skip to content
Advertisement

Loop through JSON array in PLSQL 12.1

I have JSON array inside varchar

Now if I print out arrayCars i will get

[{“name”:”Honda”,”color”:”red”},{“name”:”Toyota”,”color”:”green”}]

But how can I loop through this Cars array and print out it’s components seperately (get access to them)?

Advertisement

Answer

You can directly use SQL with JSON_TABLE() function which is available starting with Oracle DB 12.1.0.2 version such as

Demo

If you really need to use PL/SQL, then consider creating a function with SYS_REFCURSOR return type such as

and then call from SQL Developer’s console as

Edit(for your last comment):

Alternatively, you can use a simple implicit loop such as

Demo2

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement