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

by aniya.jaskolski , in category: MySQL , 7 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 , 7 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.

Related Threads:

How to convert json object rows into json array in mysql?
How to store json array in oracle?
How to update the nested array in json using oracle?
How to get 2 distinct rows from 1 row with 3 tables in sql oracle?
How to limit the number of rows displayed in phpMyAdmin?
How to fetch an unlimited number of rows in presto?