Exiting from CockroachDB SQL CLI - cockroachdb

Once I’m in the CockroachDB SQL shell, how do I get out of it? I tried exit; and quit; and it didn’t work.

You can exit from the CockroachDB SQL CLI with ctrl + C or \q.

you can also exit the CLI with quit or exit WITHOUT the training semicolon

Related

sqlplus not properly ended script

i have a plsql script, which is not properly terminated:
create or replace package mypackage
... (no semicolon/forward slash at the end)
the script is executed with sqlplus (12.1) on windows powershell:
sqlplus user/pass#host #my_not_properly_ended_file.pks
i would expect sqlplus to terminate with exit code 1 and an error message, but instead it prompts for input.
how can i get an error message and exit code in this situation?
edit: solution should also work with dml statements that are not terminated with a semicolon.
You can use shell redirection instead of #:
sqlplus user/pass#host < my_not_properly_ended_file.pks
This will also prevent it getting 'stuck' if the script doesn't end with an exit command.
However, it won't return an error code to the shell in either case. As far as SQL*Plus is concerned you put the incomplete statement into its buffer but never attempted to execute it (as there was no slash); and as it didn't run, it didn't error. So setting whenever sqlerror or whatever won't make any difference either.

Return status of a hive script

I have two questions regarding the capture of the return status/exit status of hive script.
Capture the return status in a unix script
try2.hql
select from_unixtime(unix_timestamp(),'YYYY-MM-DD')
This is called in the shell script try1.sh
echo "Start of script"
hive -f try2.hql
echo "End of script"
Now, I need to capture the return status of try2.hql. How can I do this ?
Control flow when multiple queries are available
There are a couple of hive queries in a script try3.hql
select stockname, stock_date from mystocks_stg;
select concat('Top10_Stocks_High_OP_',sdate,'_',srnk) as rowkey, sname, sdate, sprice, srnk from (
select stockname as sname, stock_date as sdate, stock_price_open as sprice,rank() over(order by stock_price_open desc) as srnk
from mystocks
where from_unixtime(unix_timestamp(stock_date,'yyyy-mm-dd'),'yyyymmdd') = '${hiveconf:batch_date}') tab
where tab.srnk <= 10;
try3.hql is called in the script try4.sh be passing the relevant parameters.
My question : In try3.hql, if there is any error in the first query, I must return to the shell script and abort the program, without executing the second script.
Please suggest.
For part 1 of your problem, you can change your script to exit the status of hive:
echo "Start of script"
hive -f try2.hql; hive_status=$?
echo "End of script"
exit $hive_status
And I have a solution for part 2.
You do know that "hive" CLI is deprecated in favor of "beeline" according to the documentation ?
HiveServer2 (introduced in Hive 0.11) has its own CLI called Beeline,
which is a JDBC client based on SQLLine. Due to new development being
focused on HiveServer2, Hive CLI will soon be deprecated in favor of
Beeline (HIVE-10511).
In beeline, by default, your script will stop as soon as there is an error in it. This is controlled by the "force" parameter.
--force=[true/false] continue running script even after errors
BTW, the solution provided by codeforester for part 1 still works with beeline.
echo "Start of script"
hive -f try2.hql
hive_status=$?
echo "End of script"
echo $hive_status>>$HOME/exit_status.log
In the home directory, you'll find the exit_status.log file created, in which you'll have the exit status of the script.

Handling ORA error in Unix shell script

I am trying to execute a script which actually runs a SQL and returns the value , write to to a CSV file and send it.
/data/oracle/product/10.2.0.4/bin/sqlplus -s user_name/password#DBName #/export/home/script/abc.sql
I want to capture the error whenever there is any error while running the SQL part but it always hangs.
I tried putting "(($?)) && ((ERRORS += 1))" after above statement but it never reaches to that line.
I want to capture the error code in a variable ERROR and exit with the error code.
Kindly help
you can put it under TRY-Catch block. refer this manual
To be able to capture the error via shell script you have to remove you error handling from your SQL and set the script to rollback and return the error:
WHENEVER OSERROR EXIT 9 ROLLBACK;
WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;

Unable to exit Hive

I've just installed Hive on my Ubuntu machine (14.04). When I run hive in the terminal, it comes up with Logging initialized using configuration in jar:file:/home/nkhl/Documents/apachehive/lib/hive-common-1.2.1.jar!/hive-log4j.properties which is fine, I guess. Then the Hive shell opens. I haven't learnt Hive (yet) so when i run quit to quit the shell, it does nothing.
Here's the version of Hive i am on now:
Hive 1.2.1
Subversion git://localhost.localdomain/home/sush/dev/hive.git -r 243e7c1ac39cb7ac8b65c5bc6988f5cc3162f558
Compiled by sush on Fri Jun 19 02:03:48 PDT 2015
From source with checksum ab480aca41b24a9c3751b8c023338231
I close the terminal off, to quit the shell. Please help!
Thanks in advance.
I guess you must have forgotten to write semi-colon at the end of quit.
Use quit or exit to leave the interactive shell as shown below. Notice semi-colon (i.e. ; )
hive> quit;
OR
hive> exit;
Here we can exit from hive shell by the following 3 commands
1.hive>exit;
2.hive>quit;
As we all know that we can connect to hiveserver2 from beeline,jdbc-odbc,trift api.So when you are using beeline shell then the first two commands will not work so its better to use the following command to exit from beeline.
!exit
no semicolon should be used
You should also be about to use ctrl+c to exit
This is the right way to quit or exit from hive session.
hive> quit;
or
hive> exit;
Not the ;
You can quit using Ctrl(key) + C(Key) or quit; at the hive shell prompt.
That should work!!
use ctr+c to exit the hive
or hive > exit;
Once you type exit without ';' then ctrl+C won't work, in this case you shall directly quit the shell by closing terminal.

How to make a sqlplus quit when database is not available?

i have a problem with sqlplus on windows batch.
I have SQLPLUS 10.2
i'm trying to connect to a database through a windows script.cmd
script.cmd only launches : sqlplus test/Test#mydatabase #script.sql
The problem is when the database is not available, the sqlplus says
ERROR:
ORA-12541: TNS:no listener
Enter user-name :
and waits for input .. and blocks the .cmd
How can i adapt the script to stop immediately when the database is not avaliable or just to avoid waiting for user prompts ?
Thanks
You can do sqlplus -l test/Test#mydatabase #script.sql; the -l flag means it will only try to connect once, and if it fails for any reason will exit instead of prompting. Look at the output of sqlplus -?, or see the documentation.
may be you should think about using TNSPING utility. You can use it within CMD script before trying to connect to db with sqlplus. In this case you should analyse its output.
You can try with 2 connects.
First one will spool result to a file.
In the second one check what is in that file. If you don't encounter ORA-12541 or any other error messages then call the second script.
You can make all these commands inside one batch script and call it with
SQLPLUS #script.sql
and inside use
connect test/Test#mydatabase

Resources