I am trying to parse a json array and its objects to further make use of them in my mysql procedure.
But while reading the values it shows null. _list will contain
[{"floor_id":"5","length":"40"},{"floor_id":"6","length":"61"}]
Code:
CREATE DEFINER=`admin`@`%` PROCEDURE `manage_room`(IN _id INT,
IN _list JSON,
INOUT v_message varchar(1000),
INOUT v_code int
)
BEGIN
declare _floor_number int ;
declare floor_list_length int;
set floor_list_length =3;
iterator:
LOOP
IF floor_list_length = 0 OR floor_list_length IS NULL THEN
LEAVE iterator;
END IF;
select JSON_EXTRACT(_rooms_list,CONCAT('$._list[', `floor_list_length`, '].floor_id')) as f ;
select JSON_EXTRACT(_rooms_list,CONCAT('$._list[', `floor_list_length`, '].length')) as l ;
insert into temp(val,txt) values (f,l);
end loop;
end
Can someone correct me what mistake i am doing?
SELECT JSON_EXTRACT(`_list`, '$[0].floor_id') as f ;._listbut you reference it as_rooms_list. Then you use$._listin the JSON path, but that key doesn't appear in the JSON content. You declare a variable_floor_numberbut you do not use it. Then you use a variablefloor_list_lengthwithout declaring it or setting a value. You try to select fields from the JSON with aliases but you don't set them to any variable. Then you usefandlas if they are variables. This procedure is totally gibberish._floor_numberand set it to 3. But there are still many other problems.