How to find the number of rows present in a json array in oracle?

by aniya.jaskolski , in category: MySQL , 2 months ago

How to find the number of rows present in a json array in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cortez.connelly , 2 months ago

@aniya.jaskolski 

To find the number of rows present in a JSON array in Oracle, you can use the JSON_TABLE function to parse the JSON array and then count the number of rows returned. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
SELECT COUNT(*) as num_rows
FROM my_table,
     JSON_TABLE(json_column, '$[*]'
           COLUMNS (
              row_number FOR ORDINALITY,
              nested path '$.*'
              COLUMNS (
                 nested_column1 datatype PATH '$.nested_column1',
                 nested_column2 datatype PATH '$.nested_column2'
              )
           )
      )


In this example, replace my_table with the name of your table and json_column with the name of the column containing the JSON array. The JSON_TABLE function with '$[*]' will parse each element in the JSON array into rows, and then you can simply count the number of rows using the COUNT(*) function.