mjk
mjk

Reputation: 31

what is Oracle command 'o;'

I am using the oracle version.

Oracle Database 11g Release 11.2.0.1.0

I accidentally ran the command o; in oracle delveloper.

The result is as below.

The PL/SQL procedure completed successfully.

not spooling currently
The sqlcl_int_runme alias has been removed.

I don't know what I did....

First of all, there seems to be no problem with basic table CRUD.

Has anyone had this experience? I need an explanation of what happened...

Upvotes: 3

Views: 2020

Answers (1)

thatjeffsmith
thatjeffsmith

Reputation: 22467

It's an alias.

We copied over some popular commands from postgresql to SQLcl, one of those was 'o'

From the post docs

\o or \out [ filename ] \o or \out [ |command ] Arranges to save future query results to the file filename or pipe future results to the shell command command. If no argument is specified, the query output is reset to the standard output.

If the argument begins with |, then the entire remainder of the line is taken to be the command to execute, and neither variable interpolation nor backquote expansion are performed in it. The rest of the line is simply passed literally to the shell.

“Query results” includes all tables, command responses, and notices obtained from the database server, as well as output of various backslash commands that query the database (such as \d); but not error messages.

SQL> alias
\!          \?          \c          \cd         \d          \dp         \dt         \dt+        \e          \echo       \encoding   \i
\o          \p          \prompt     \q          \qecho      \r          \save       \timing     \w          \z          clear       cls
cpu         fuzzy       gglag       locks       sessions    tables      tables2     topsql
SQL> alias list \o
\o NULLDEFAULTS psql - desc \o [FILE_NAME] - turn spool log file on (or off if no FILE_NAME given)
--------------------------------------------------------------------------------------------------


Declare
  maxpos number:=null;
BEGIN
  if (:sqlcl_int_first is null) then
    :sqlcl_int_runme:='spool off';
  else
    :sqlcl_int_runme:='spool '||:sqlcl_int_first||' ';
  end if;
end;
/
alias NULLDEFAULTS sqlcl_int_runme=:sqlcl_int_runme;
sqlcl_int_runme
alias drop sqlcl_int_runme

To see it in action...

SQL> set sqlformat csv
SQL> o stackoverflow.csv

PL/SQL procedure successfully completed.

Alias sqlcl_int_runme dropped
SQL> select * from regions;
"REGION_ID","REGION_NAME"
1,"Europe"
2,"Americas"
3,"Asia"
4,"Middle East and Africa"

SQL> o

PL/SQL procedure successfully completed.

Alias sqlcl_int_runme dropped
SQL> !dir stackoverflow.csv
 Volume in drive C is System
 Volume Serial Number is F897-6A6F

 Directory of c:\sqlcl\22.2.1\sqlcl\bin

08/30/2022  08:09 AM               170 stackoverflow.csv
               1 File(s)            170 bytes
               0 Dir(s)  190,156,173,312 bytes free

SQL> !type stackoverflow.csv
Alias sqlcl_int_runme dropped
"REGION_ID","REGION_NAME"
1,"Europe"
2,"Americas"
3,"Asia"
4,"Middle East and Africa"


PL/SQL procedure successfully completed.

Upvotes: 6

Related Questions