1:json數據格式以下sql
{ "Order": [{ "orderType": "LSCK", "amount": "376.00", "orderId": "18090501706539", "orderCreateTime": "2018-09-05 10:21:49", "brandID": null, "customerCode": "01.01.0002.001", "extendProps": "{\"purotton\":{\"khmc\":\"nutrilon官方旗艦店\",\"ecProvince\":\"江西省\",\"xfClientCode\":\"\",\"activity\":[],\"ecCity\":\"上饒市\",\"sellerMsg\":\"\",\"orderStatus\":\"已完成\",\"actualFromLoc\":\"03.01\",\"intOrderId\":\"160023\",\"ecCounty\":\"鄱陽縣\",\"ecAddress\":\"江西省 上饒市 鄱陽縣 昌洲鄉昌洲大橋。\",\"extraAmountFlag\":\"N\",\"payMsg\":\"\",\"otherDiscountFee\":\"0.00\",\"xfTotalCashRecAmount\":\"376.00\",\"ecCustomerName\":\"程青青\",\"xfSellingAmountActual\":\"376.00\",\"xfPostDate\":\"2018-09-05 14:39:06\",\"xfSpecificedType\":\"alipay\",\"chargeNum\":\"yjr青青\",\"xfSalesman\":\"5\",\"comments\":\"0\",\"xfCreateTime\":\"2018-09-05 10:21:49\",\"outChannelFlag\":\"Y\",\"ecCustomerPhone\":\"15968140210\",\"intMemberId\":\"121406\",\"pointFlag\":\"N\",\"docActualAmount\":\"376.00\",\"lylx\":\"淘寶\",\"transactionDate\":\"2018-09-05 10:26:29\",\"xfChangeAmount\":0,\"xfSellingAmount\":\"376.00\",\"xfNetqty\":\"2\",\"docPaymentMethod\":\"3\",\"transactionType\":\"ORD\",\"codFLag\":\"N\",\"docAmount\":\"376.00\",\"createTime\":\"2018-09-05 10:21:49\",\"xfDeliveryFee\":\"0.00\",\"currencyCode\":\"RMB\"},\"receiverInfo\":{\"zip\":\"000000\",\"country\":\"中國\",\"shippingCode\":\"yunda\",\"shippingName\":\"韻達快運\",\"payTime\":\"2018-09-05 10:26:29\",\"city\":\"上饒市\",\"idCard\":\"\",\"mobile\":\"15968140210\",\"remark\":\"\",\"receiverAddress\":\"江西省 上饒市 鄱陽縣 昌洲鄉昌洲大橋。\",\"shippingSn\":\"3900261353988\",\"shippingFee\":\"0.00\",\"province\":\"江西省\",\"createTime\":\"2018-09-05 10:21:49\",\"district\":\"鄱陽縣\",\"name\":\"程青青\",\"tel\":\"\",\"shippingTime\":\"2018-09-05 14:39:06\",\"payCode\":\"alipay\",\"payName\":\"支付寶\",\"account\":\"yjr青青\"},\"isGive\":0,\"dealCode\":\"213651422037732931\"}", "orderCode": "18090501706539", "remark": "", "actualQty": "2", "warehouseCode": "03.01", "channelCode": "000" }], "orderLine": [{ "colorName": "通色", "amount": "376", "orderId": "213651422037732931", "itemCode": "01.01.02.99.01.05.0001", "discount": "1.0000", "purchasePrice": null, "styleName": "諾優能嬰兒配方奶粉 900g(0-6月齡,1段)", "styleCode": "01.01.02.99.01.05.0001", "actualQty": 2, "skuProperty": null, "itemId": "01.01.02.99.01.05.0001", "itemName": "諾優能嬰兒配方奶粉 900g(0-6月齡,1段)", "sizeName": "通碼", "stdprice": "188.00", "extendProps": "{\"purotton\":{\"intOrderLineId\":\"179513\",\"shareShippingFee\":\"0.00\",\"shareOtherDiscountFee\":\"0.00\",\"shopPrice\":\"188.00\",\"actualPrice\":\"188.00\",\"qty\":\"2\",\"goodsPrice\":\"188.00\",\"discount\":\"1.0000\",\"discountAmount\":\"0.00\",\"standardPrice\":\"0.00\",\"productNum\":\"01.01.02.99.01.05.0001\"}}", "colorCode": "000", "sizeCode": "000", "retailPrice": "0.00" }] }
2:傳入以下存儲過程,進行解析,並寫入相關表中(其中解析extendProps關鍵字,此關建字內容爲json格式內容,需轉化爲json格式,進行解析相關字段)數據庫
CREATE OR REPLACE PROCEDURE oms_order_gen1(p_json_varchar IN CLOB, p_code OUT NUMBER, p_message OUT VARCHAR2) AS ---------------------------------------------------------- --author:xuyang --date:20180718 --description: --調用奇門[OMS訂單明細]接口,若是傳入的orderType爲LSCK,則將對應的資料寫入到中間表[OMS訂單明細(正常零售) OMS_ORDER]; --若是orderType爲LSTH,則將對應的資料寫入到中間表[OMS訂單明細(零售退貨) OMS_RETORDER] --author:xuyang --date:20180906 --description:客戶需求變化:相關字段對應及取值變化 ---------------------------------------------------------- v_injson json; v_bodylist json_list; --明細信息json列表 v_onejson json; --用於解析每個明細數據 --要插入的記錄變量 v_omsdocno oms_order.omsdocno%TYPE; --單據號 v_billdate oms_order.billdate%TYPE; --單據日期 v_doctype oms_order.doctype%TYPE; --庫存類型 v_qty oms_order.qty%TYPE; --數量 v_productalias_no oms_order.productalias_no%TYPE; v_tot_amt_actual oms_order.tot_amt_actual%TYPE; v_priceactual oms_order.priceactual%TYPE; v_olddocno oms_order.olddocno%TYPE; v_htprice oms_order.htprice%TYPE; v_code oms_order.code%TYPE; v_storecode oms_order.storecode%TYPE; v_count NUMBER(10); v_xftillid oms_order.omsdocno%TYPE; v_remark oms_order.remark%TYPE; v_isgive oms_order.isgive%TYPE; v_string VARCHAR2(4000); v_exdpos json; v_transactiondate oms_retorder.billdate%TYPE; v_injson_orderlist json_list; v_injson_order json; BEGIN --將接口信息轉化爲json格式 v_injson := json(p_json_varchar); --begin modified by xy 20180906 v_injson_orderlist := json_ext.get_json_list(v_injson, 'Order'); v_injson_order := json(v_injson_orderlist.get_elem(1)); --獲取要插入頭表的字段信息 v_doctype := json_ext.get_string(v_injson_order, 'orderType'); v_olddocno := json_ext.get_string(v_injson_order, 'orderId'); v_storecode := json_ext.get_string(v_injson_order, 'warehouseCode'); v_remark := json_ext.get_string(v_injson_order, 'remark'); v_code := json_ext.get_string(v_injson_order, 'customerCode'); --begin added by xy 20180905 v_string := json_ext.get_string(v_injson_order, 'extendProps'); v_exdpos := json(v_string); v_billdate := to_number(REPLACE(substr(json_ext.get_string(v_exdpos, 'purotton.shippingTime'), 1, 10), '-', '')); v_omsdocno := json_ext.get_string(v_exdpos, 'purotton.dealCode'); v_isgive := json_ext.get_string(v_exdpos, 'purotton.isGive'); --retorder columns v_transactiondate := to_number(REPLACE(substr(json_ext.get_string(v_exdpos, 'purotton.transactionDate'), 1, 10), '-', '')); v_xftillid := json_ext.get_string(v_exdpos, 'purotton.xfTillid'); --end added by xy 20180905 IF v_doctype = 'LSCK' THEN --訂單號已存在,不容許 BEGIN SELECT COUNT(a.id) INTO v_count FROM oms_order a WHERE a.olddocno = v_olddocno; EXCEPTION WHEN no_data_found THEN v_count := 0; END; IF v_count >= 1 THEN p_code := 0; p_message := 'failed,Omsorder existed in system'; RETURN; END IF; --獲取數據,插入到表oms_order中 v_bodylist := json_list(); v_onejson := json(); --獲取orderLine v_bodylist := json_ext.get_json_list(v_injson, 'orderLine'); --循環獲取明細數據,並插入數據庫中 FOR idx IN 1 .. v_bodylist.COUNT LOOP --讀取每一個明細信息 v_onejson := json(v_bodylist.get_elem(idx)); v_productalias_no := json_ext.get_string(v_onejson, 'itemCode'); v_qty := to_number(json_ext.get_string(v_onejson, 'actualQty')); v_htprice := to_number(json_ext.get_string(v_onejson, 'retailPrice')); v_priceactual := to_number(json_ext.get_string(v_onejson, 'stdprice')); v_tot_amt_actual := to_number(json_ext.get_string(v_onejson, 'amount')); --插入表 INSERT INTO oms_order (id, ad_client_id, ad_org_id, billdate, omsdocno, doctype, olddocno, productalias_no, qty, htprice, priceactual, tot_amt_actual, recivedate, recivestatus, errmsg, ownerid, creationdate, modifierid, modifieddate, isactive, code, storecode, remark, isgive) VALUES (get_sequences(upper('oms_order')), 37, 27, v_billdate, v_omsdocno, v_doctype, v_olddocno, v_productalias_no, v_qty, v_htprice, v_priceactual, v_tot_amt_actual, SYSDATE, 80, NULL, 893, SYSDATE, 893, SYSDATE, 'Y', v_code, v_storecode, v_remark, v_isgive); END LOOP; ELSIF v_doctype = 'LSTH' THEN --訂單號已存在,不容許 BEGIN SELECT COUNT(a.id) INTO v_count FROM oms_retorder a WHERE a.olddocno = v_olddocno; EXCEPTION WHEN no_data_found THEN v_count := 0; END; IF v_count >= 1 THEN p_code := 0; p_message := 'failed,Retorder existed in system'; RETURN; END IF; --獲取數據,插入到表oms_retorder中 v_bodylist := json_list(); v_onejson := json(); --獲取body:orderBody v_bodylist := json_ext.get_json_list(v_injson, 'orderLine'); --循環獲取明細數據,並插入數據庫中 FOR idx IN 1 .. v_bodylist.COUNT LOOP --讀取每一個明細信息 v_onejson := json(v_bodylist.get_elem(idx)); v_productalias_no := json_ext.get_string(v_onejson, 'itemCode'); v_qty := to_number(json_ext.get_string(v_onejson, 'actualQty')); v_htprice := to_number(json_ext.get_string(v_onejson, 'retailPrice')); v_priceactual := to_number(json_ext.get_string(v_onejson, 'stdprice')); v_tot_amt_actual := to_number(json_ext.get_string(v_onejson, 'amount')); --插入表 INSERT INTO oms_retorder (id, ad_client_id, ad_org_id, billdate, omsdocno, doctype, olddocno, productalias_no, qty, htprice, priceactual, tot_amt_actual, recivedate, recivestatus, errmsg, ownerid, creationdate, modifierid, modifieddate, isactive, origcode, storecode, remark, isgive) VALUES (get_sequences(upper('oms_retorder')), 37, 27, v_transactiondate, v_xftillid, v_doctype, v_olddocno, v_productalias_no, v_qty, v_htprice, v_priceactual, v_tot_amt_actual, SYSDATE, 80, NULL, 893, SYSDATE, 893, SYSDATE, 'Y', v_code, v_storecode, v_remark, v_isgive); END LOOP; END IF; --end modified by xy 20180906 p_code := 1; p_message := 'success'; END;