How to JSON extract from dynamic key value pair in MySQL?

前端 未结 4 2126
暖寄归人
暖寄归人 2021-01-25 22:40

I have the user table with user_id and user_details. it contains the JSON data in string format as shown below:

[{\"name\":\"question-1\",\"value\":\"sachin\",\"         


        
4条回答
  •  天涯浪人
    2021-01-25 23:11

    I was working in a report where there was a big json array list in one column. I modified the datamodel to store the relationship 1 to * instead of storing everything in one single column. For doing this process, I had to use a while in a stored procedure since I do not know the maximum size:

    DROP PROCEDURE IF EXISTS `test`;
    
    DELIMITER #
    
    CREATE PROCEDURE `test`()
    PROC_MAIN:BEGIN
    DECLARE numNotes int;
    DECLARE c int;
    DECLARE pos varchar(10);
    
    SET c = 0;
    SET numNotes = (SELECT 
    ROUND (   
            (
                LENGTH(debtor_master_notes)
                - LENGTH( REPLACE ( debtor_master_notes, "Id", "") ) 
            ) / LENGTH("Id")        
        ) AS countt FROM debtor_master
    order by countt desc Limit 1);
    
    DROP TEMPORARY TABLE IF EXISTS debtorTable;
    CREATE TEMPORARY TABLE debtorTable(debtor_master_id int(11), json longtext, note int);
    WHILE(c 

提交回复
热议问题