Thursday, April 13, 2023

set jsonprint new feature in SQL*Plus client

 
New feature introduced in Oracle 21c sql*plus client is formatting the output of JSON type columns.
Starting with Oracle 21c, JSON is the newly introduced datatype for handling JSON data in SQL and PL/SQL programming.
 
The “pretty” option, displays a formatted JSON output with proper alignment and spacing.
The default is “normal” which clears the proper alignment and spacing.
 
demo@PDB1> show jsonprint
jsonprint NORMAL
demo@PDB1> select json_arrayagg( json_object(*) returning json ) from dept;
 
JSON_ARRAYAGG(JSON_OBJECT(*)RETURNINGJSON)
--------------------------------------------------------------------------------
[{"DEPTNO":10,"DNAME":"ACCOUNTING","LOC":"NEW YORK"},{"DEPTNO":20,"DNAME":"RESEA
RCH","LOC":"DALLAS"},{"DEPTNO":30,"DNAME":"SALES","LOC":"CHICAGO"},{"DEPTNO":40,
"DNAME":"OPERATIONS","LOC":"BOSTON"}]
 
demo@PDB1> set jsonprint pretty
demo@PDB1> show jsonprint
jsonprint PRETTY
demo@PDB1> select json_arrayagg( json_object(*) returning json ) from dept;
 
JSON_ARRAYAGG(JSON_OBJECT(*)RETURNINGJSON)
--------------------------------------------------------------------------------
[
  {
    "DEPTNO" : 10,
    "DNAME" : "ACCOUNTING",
    "LOC" : "NEW YORK"
  },
  {
    "DEPTNO" : 20,
    "DNAME" : "RESEARCH",
    "LOC" : "DALLAS"
  },
  {
    "DEPTNO" : 30,
    "DNAME" : "SALES",
    "LOC" : "CHICAGO"
  },
  {
    "DEPTNO" : 40,
    "DNAME" : "OPERATIONS",
    "LOC" : "BOSTON"
  }
]
 
 

No comments:

Post a Comment