如何在oracle apex服务器端的restapi post方法中检索json数据?

问题描述 投票:0回答:1

Json数据如下。这是

print(jsonEncode(requestData))

的输出

{"mData":{"L":2,"B":1,"D":1},"day":"2024-02-17 00:00:00.000Z"}

颤动代码

try {
http.Response response = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(requestData),
);

我想用这个值进行一些更新操作。

   update t1 set count = 2 where m_type='L' and day='2024-02-17'
   update t1 set count = 1 where m_type='B' and day='2024-02-17'
   update t1 set count = 1 where m_type='D' and day='2024-02-17'

我尝试过这个但不起作用。

我面对

Status code: 555

我可以像

{username: username, password: pass}
一样访问一层json,但无法访问如上所示的两层json。

我在oracle apex中尝试过这个。

    DECLARE
    p_m_type t1.m_type%TYPE;
    p_count t1.count%TYPE;
    BEGIN
    FOR i IN 1..:mData.count LOOP
        p_m_type := :mData(i).meal_type;
        p_count := :mData(i).count;

        UPDATE t1
        SET count = p_count
        where day = :day
        AND m_type = p_m_type;
        
     END LOOP;
     EXCEPTION
     WHEN OTHERS THEN
        ROLLBACK;
        RAISE;
    END;

day
DATE
型柱。

提前致谢。

json rest post plsql oracle-apex
1个回答
0
投票

您应该使用 JSON_TABLE() 函数从 json 中提取数据:

--      S a m p l e    D a t a :
Select    jt.L, jt.B, jt.D, To_Date( SubStr(DAY_ID, 1, 10), 'yyyy-mm-dd' ) "DAY_ID"
From      JSON_TABLE( '{"mData":{"L":2,"B":1,"D":1},"day":"2024-02-17 00:00:00.000Z"}',
                      '$'
                      COLUMNS ( L      Number(3)    PATH '$.mData.L', 
                                B      Number(3)    PATH '$.mData.B', 
                                D      Number(3)    PATH '$.mData.D', 
                                DAY_ID VarChar2(32) PATH '$.day' 
                              )
                    ) jt
/*      R e s u l t :
         L          B          D DAY_ID  
---------- ---------- ---------- ----------
         2          1          1 2024-02-17   */
© www.soinside.com 2019 - 2024. All rights reserved.