Oracle has some packages that will dump objects in SQL format, such as dbms_metadata.set_transform_param. One option that can be set is to "pretty print" the SQL.

Is there anything in Oracle that will pretty print a random SQL query string? Something like:

select pretty_print('select * from emp;') sql from dual;

'select *
   from emp;'
  • As in you want a randomly generated string of a variable length that is returned in a pretty print format? – Ali Razeghi Mar 30 '15 at 21:31
  • @AliRazeghi, yes that would be perfect. – Mark Harrison Mar 30 '15 at 21:46
  • 1
    There is no such feature inside the database. Oracle's SQL client "SQL Developer" can do that though – a_horse_with_no_name Mar 30 '15 at 22:21
  • If the given SQL will correctly parse ok in your current database, you might be able to use DBMS_SQL.PARSE to get it into the shared pool without executing it, then use DBMS_METADATA to pretty print it. Obviously won't work if the statement won't parse in the current session due to missing objects. – Philᵀᴹ Mar 31 '15 at 8:14
  • Just don't parse a DDL using dbms_sql.parse. IIRC it would execute it unless behavior changed in recent versions. – Raj Mar 10 '17 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.