Created
June 26, 2017 21:47
-
-
Save tmuth/455f6a1d2bf2869f3dc881d9e8f86851 to your computer and use it in GitHub Desktop.
Oracle get 1 row as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT regexp_replace(xml3,'(.+),.+$','{\1}',1,1,'n') xml4 | |
FROM | |
(SELECT regexp_replace(xml2,'<(\w+)>(.+)</\1>','"\1" : "\2",',1,0,'n') xml3 | |
FROM | |
(SELECT regexp_replace(xml,'(^.+<ROW>)(.*)(</ROW>.*)','\2',1,1,'n') xml2 | |
FROM | |
(SELECT dbms_xmlgen.getXML('SELECT * from soe.customers where rownum=1') xml | |
FROM dual | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
{ "CUSTOMER_ID" : "50865", "CUST_FIRST_NAME" : "marco", "CUST_LAST_NAME" : "hamilton", "NLS_LANGUAGE" : "EG", "NLS_TERRITORY" : "Belgium", "CREDIT_LIMIT" : "5000", "CUST_EMAIL" : "[email protected]", "ACCOUNT_MGR_ID" : "389", "CUSTOMER_SINCE" : "25-MAR-04", "CUSTOMER_CLASS" : "Occasional", "SUGGESTIONS" : "Health", "DOB" : "17-MAY-94", "MAILSHOT" : "Y", "PARTNER_MAILSHOT" : "Y", "PREFERRED_ADDRESS" : "190107", "PREFERRED_CARD" : "137430"}