1
我想從「response.AAPL.results.year_high.data」中提取值,因爲有兩個值。我發現了很多例子,但數據中的值括號都是通過標題單獨標識的,而我的不是。有誰知道如何訪問這些信息?PL/SQL中的APEX_JSON.get_varchar2
in Oracle 12
在此先感謝。
create or replace procedure test(p_where in varchar2, p_radius in number, p_room in number)
is
begin
DECLARE
l_param_list VARCHAR2(512);
l_http_request UTL_HTTP.req;
l_http_response UTL_HTTP.resp;
l_response_text VARCHAR2(32767);
l_members WWV_FLOW_T_VARCHAR2;
l_count PLS_INTEGER;
l_list json_list;
obj json := json();
l_json_values apex_json.t_values;
arr json_list := json_list();
l_paths apex_t_varchar2;
BEGIN
l_response_text := '{"response": {"AAPL": {"meta": {"status": "ok"}, "results": {"year_high": {"meta": {"status": "ok"}, "data": [["2016-09-30", 123.8200], ["2016-09-29", 125.0000]]}}}, "MSFT": {"meta": {"status": "ok"}, "results": {"year_high": {"meta": {"status": "ok"}, "data": ["2016-09-30", 58.7000]}}}}}';
/* DBMS_OUTPUT.put_line(l_response_text);*/
apex_json.parse (l_response_text);
/* dbms_output.put_line (apex_json.get_varchar2(p_path => 'count')); */
/* dbms_output.put_line (apex_json.get_number (p_path => 'response.MSFT.results.price.data',p0=>2,p_values =>l_json_values));*/
DBMS_OUTPUT.put_line('----------------------------------------');
DBMS_OUTPUT.put_line('Check elements (members) below a path');
l_members := APEX_JSON.get_members(p_path=>'response.AAPL.results.year_high');
DBMS_OUTPUT.put_line('Members Count : ' || l_members.COUNT);
FOR i IN 1 .. l_members.COUNT LOOP
DBMS_OUTPUT.put_line('Member Item Idx : ' || i);
DBMS_OUTPUT.put_line('Member Name : ' || l_members(i));
END LOOP;
/* This is were I would like to extract the value in the data member*/
DBMS_OUTPUT.put_line('----------------------------------------');
DBMS_OUTPUT.put_line('Employee Information (Loop through array)');
l_count := APEX_JSON.get_count(p_path => 'response.AAPL.results.year_high.data');
DBMS_OUTPUT.put_line('Employees Count : ' || l_count);
FOR i IN 1 .. l_count LOOP
DBMS_OUTPUT.put_line('Employee Item Idx : ' || i);
DBMS_OUTPUT.put_line('Employee Number : ' ||
APEX_JSON.get_varchar2(p_path => 'response.AAPL.results.year_high.data[%d]', p0 => i));
DBMS_OUTPUT.put_line('Employee Name : ' ||
APEX_JSON.get_varchar2(p_path => 'response.AAPL.results.year_high.data[%d]', p0 => i));
END LOOP;
/* dbms_output.put_line (apex_json.get_varchar2 ('response.MSFT.results.year_high.data[%d]', 1));
dbms_output.put_line (apex_json.get_varchar2('response.MSFT.results.year_high.data[%d]', 2));
dbms_output.put_line (apex_json.get_varchar2 ('response.AAPL.results.year_high.data[%d]',1));
dbms_output.put_line (apex_json.get_varchar2('response.AAPL.results.year_high.data[%d]',2));
*/
end;
end test;
謝謝奧拉維爾。長話短說,結果是由一家公司提供的,所以我無法控制格式。這就是我一直在努力尋找訪問數據的方式的原因。我能夠從使用APEX製作的帖子中提取數據。有沒有辦法使用遊標(循環),使用我的價值? –
至於格式,我認爲我沒有任何控制權,但我可能是錯的,因爲我是綠色的APEX。 –
我已通過添加for循環示例來獲取數據來更新答案。 –