sql >> Database >  >> RDS >> Oracle

werk met json in orakel

Ik ben deze bibliotheek gaan gebruiken en het lijkt veelbelovend:https://github.com/pljson/pljson

Eenvoudig te installeren en de voorbeelden zijn goed.

Om de bibliotheek in uw voorbeeld te gebruiken, voegt u deze variabelen toe aan uw procedure..

mapData     json;
results     json_list;
status      json_value;
firstResult json;
geometry    json;

....

Vervolgens kunt u het antwoord als een json-object manipuleren.

-- convert the result from the get to a json object, and show some results.
mapData := json(v_ans);

-- Show the status of the request
status := mapData.get('status');
dbms_output.put_line('Status = ' || status.get_string());

IF (status.get_string() = 'OK') THEN
  results := json_list(mapData.get('results'));
  -- Grab the first item in the list
  resultObject := json(results.head);

  -- Show the human readable address 
  dbms_output.put_line('Address = ' || resultObject.get('formatted_address').to_char() );
  -- Show the json location data 
  dbms_output.put_line('Location = ' || resultObject.get('geometry').to_char() );
END IF;

Als u deze code uitvoert, wordt dit uitgevoerd naar de dbms-uitvoer:

Status = OK
Address = "St Paul, MN 55105, USA"
Location = {
  "bounds" : {
    "northeast" : {
      "lat" : 44.9483849,
      "lng" : -93.1261959
    },
    "southwest" : {
      "lat" : 44.9223829,
      "lng" : -93.200307
    }
  },
  "location" : {
    "lat" : 44.9330076,
    "lng" : -93.16290629999999
  },
  "location_type" : "APPROXIMATE",
  "viewport" : {
    "northeast" : {
      "lat" : 44.9483849,
      "lng" : -93.1261959
    },
    "southwest" : {
      "lat" : 44.9223829,
      "lng" : -93.200307
    }
  }
}


  1. Welke rijen worden geretourneerd bij gebruik van LIMIT met OFFSET in MySQL?

  2. Wat hebben poker, blackjack, Belot en Préférence met databases te maken?

  3. Opgeslagen MySQL-procedures maken en gebruiken - een zelfstudie

  4. Waarde verhogen in MySQL-updatequery