what is Oracle command 'o;' - oracle

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...

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.

Related

sqlplus query with comment giving duplicate rows

Updating my question:
When I run this query from unix using sqplus it gives me duplicate outputs
Query:
select sysdate from dual
/
/*comment*/
EXIT
Output
SQL> #tt.sql
12-AUG-16
12-AUG-16
Here is what is happening.
The first two lines (including the /) form a complete SQL statement. SQLPlus executes it and displays the first line.
Then /*comment*/ is OUTSIDE the SQL statement. So it is interpreted by SQLPlus, not as a SQL comment.
The point is, comments in the SQLPlus scripting language have a different syntax; they are lines that begin with REM[ARK]. /*comment*/ is NOT a comment in SQLPlus.
Instead, in SQLPlus, a slash / as the first character on a new line means repeat the last SQL command (if after that you had SQLPlus commands, like DESCRIBE or COLUMN, those are ignored). Everything AFTER the slash is ignored. To convince yourself of this, try again, but with the comment line changed to /*comment* (delete the second slash). You will see the same result.
Then you have the command EXIT, but since it is NOT followed by a slash, it is not seen as a completed command. If I copy and paste your code in my SQLPlus window, I get the screenshot below. However, if at this point you press ENTER (or if this was in a sql script and not copied and pasted from a text editor), the SQLPlus window would shut down.
Hope this helps!
SQL> select sysdate from dual
2 /
SYSDATE
----------
2016-08-12
1 row selected.
Elapsed: 00:00:00.00
SQL> /*comment*/
SYSDATE
----------
2016-08-12
1 row selected.
Elapsed: 00:00:00.01
SQL> EXIT

Ubuntu Shell Script for ORACLE db

I'm new to working with ORACLE over SSH (putty) terminal on an Ubuntu OS, my workstation has Windows OS.
I'm programming a shell that connects to the oracle DB then exports a table into a text file and then delete some records depending on a column´s value.
No SQL Plus is installed and this is a must because we need to simulate the infraestructure of our client.
This is part of the script's code:
#!/bin/bash
su oracle
export ORACLE_SID=ORA_SID
export ORACLE_HOME=/uxx/app/oracle/product/11.2.0/client_1
export TWO_TASK=[hostname]:[port]/[ORA_SID]
isql -v [db] [user] [pass] <<EOF
CREATE OR REPLACE DIRECTORY test AS '/xxx/yyy/';
DECLARE
f utl_file.file_type;
BEGIN
f := utl_file.fopen('TEST','sample.txt','W');
for s in (select * from [table]);
loop
utl_file.put_line(f,s);
end loop;
utl_file.fclose(f);
END;
quit;
exit
EOF
When I run the script I got the following output:
SQL> SQLRowCount returns -1
SQL> [S1000][Oracle][ODBC][Ora]ORA-06550: line 1, column 7:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
[ISQL]ERROR: Could not SQLExecute
SQL> [37000][Oracle][ODBC][Ora]ORA-00900: invalid SQL statement
[ISQL]ERROR: Could not SQLExecute
SQL> [S1000][Oracle][ODBC][Ora]ORA-06550: line 1, column 5:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
[ISQL]ERROR: Could not SQLExecute
SQL> [37000][Oracle][ODBC][Ora]ORA-00900: invalid SQL statement
[ISQL]ERROR: Could not SQLExecute
SQL> [37000][Oracle][ODBC][Ora]ORA-00900: invalid SQL statement
[ISQL]ERROR: Could not SQLExecute
SQL> [37000][Oracle][ODBC][Ora]ORA-00900: invalid SQL statement
Any help would be greatly appreciated.
It resulted SqlPlus was indeed installed on the system but since it has been years since the last time I worked on UNIX like system I didn't know how to make the application work.
I first exported the bin path to my looged session:
export PATH=$ORACLE_HOME/bin:$PATH
Then I could run the sql plus and use the spool tool.
sqlplus usr/pass
Now with SqlPlus I can just use the regular spool command.
Thanks all who helped.

Generating procedure logfile and inserting date time

Friends...
DB: Oracle11gR2
OS: Linux
I have created package with couple of procedure, procedure executes alter table move... , index rebuild command on database.
I'm doing below
Run ksh shell script -> execute procedure
Procedure runs alter table, rebuild index commands on database
Procedure completes
Shell script ends.
I can generate logfile for the shell script but whatever gets executed by procedure doesn't get recorded inside shell script logfile. I understood since db session created by procedure it won't record anything in shell logfile.
So how can I
Record everything in logfile which is executed by both procedures in the same package?
Also trying to put current datetime within procedure dmbs_out.put_line command?
Is it possible to run both procedure after connecting database once instead of 2 time connecting database and executing procedure?
There might be table/table partition move syntax error but I'm only trying to trap when table move started and when finished with datetime so to identify total time taken.
*** ksh script
#!/bin/ksh
...
...
...
$LOG_FILE = move_tbs.log
echo -e "set serveroutput on\n exec move_tbs.moveTable;"|$ORACLE_HOME/bin/sqlplus/#db_alias | head -l
echo -e "set serveroutput on\n exec move_tbs.moveTablePart;"|$ORACLE_HOME/bin/sqlplus/#db_alias | head -l
DB Package / Procedure
*** Procedure
create or replace package move_all
procedure moveTable
dbms_output.put_line("CURRENT TIME" 'alter table '|| owner || '.' || table_name || 'move');
Execute immediate 'alter table '|| owner || '.' || table_name || 'move';
dbms_output.put_line("COMPLETED TIME" : CURRENT_TIME);
end moveTable;
-------------------------------------------
procedure moveTablePart
dbms_output.put_line("CURRENT TIME" 'alter table '|| owner || '.' || table_name || 'move');
Execute immediate 'alter table '|| owner || '.' || table_name || 'move partition';
dbms_output.put_line("COMPLETED TIME" : CURRENT_TIME);
end moveTablePart;
end move_all
/
You could just put both exec commands in your echo construct. But you can use a 'heredoc' to simplify running both together, and it's a easier to read and maintain too. Something like:
LOG_TBS_MOVE=move_tbs.log
(
$ORACLE_HOME/bin/sqlplus -s -l user/passwd#db_alias <<!EOF
set serveroutput on
exec move_tbs.moveTable;
exec move_tbs.moveTablePart;
exit
!EOF
) > $LOG_TBS_MOVE
The herdoc start and end markers in this example !EOF - have to match exactly. They can be anything you like as long as there's no chance of anything inside the heredoc accidentally ending it. And the end marker has to be at the start of a line, it can't be indented.
The parentheses around the SQL*Plus and heredoc can enclose multiole commands and all output from within them goes into the log. They aren't really necessary here as there is only one command inside but it's a fairly clear way of doing the redirection, I think.
I'm only putting stdout into the $LOG_TBS_MOVE file; anything on stderr (which will not include any SQL errors) will still go to screen or to your main log if you redirect stderr for that.
To show the time in your output, don't enclose the current_time part in quotes, use string concatenation, and use the right function:
dbms_output.put_line(to_char(sysdate, 'HH24:MI:SS') ||
'alter table '|| owner || '.' || table_name || 'move');
dbms_output.put_line('COMPLETED TIME: ' || to_char(sysdate, 'HH24:MI:SS'));
Or you could display the time from the shell instead, within the parentheses; that would also then go into the same log file.
You haven't shown a username or password in your SQL*Plus calls; you probably just hid them, but if you are connecting as SYS via /, you really shouldn't be creating objects in that schema. Create a new schema and work in that.

PL SQL output is not getting displayed

I have fairly simply code ..running in Oracle Virtualbox. However for some reason it is not displaying pl/sql output.
Here is code snippet
SQL> set serveroutput on
SQL> list
1 Create or Replace procedure mytz
2 IS
3 v_mytz TIMESTAMP WITH TIME ZONE DEFAULT '2013-05-05 12:00:00 AM';
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE ('Default timestamp is ' );
6* end mytz ;
SQL> /
Procedure created.
SQL>
Is there anything I need to do special to see the output on SQL prompt ?
You have to actually run the procedure, not just create it, e.g.:
set serverputput on
exec mytz;
The set serveroutput SQL*Plus command has to be in the session the procedure is executed, not the one where it is created (if they are different).
You are not showing the value of your variable at the moment; maybe you wanted this?
dbms_output.put_line('Default timestamp is: ' || v_mytz);

Long PL/SQL output in SQLPLUS

Got problem with executing my script under SQLPLUS. Under SQL Developer it works well.
set serveroutput on size 1000000
declare
yyy varchar2(32000):='';
begin
yyy := 'XxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzz';
yyy := yyy || 'XxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzz';
yyy := yyy || 'XxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzz';
dbms_output.put_line(yyy);
end;
/
Under SQLPLUS I get error:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 1
Any solution how to force running scripts with long output under SQLPLUS? I need output on because I spool results to file.
You are using a Oracle client older than Oracle 10g against an Oracle 10g Database
Please find the quote from ASKTOM below
The problem is NOT during runtime, you are apparently using an old client against a 10.2 or above database. The database code runs fine
It is when the client goes to PICK UP THE STRING from the database that you are hitting the exception.
sqlplus is doing something like this:
a) call procedure/code - it runs and fills a dbms_output buffer, an array in a package.
b) then sqlplus calls dbms_output.GET_LINES to get the buffered output to print. THIS is the call that fails.
For more information Kindly refer
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1011431134399

Resources