-1

I run the following command to connect to a remote db:

/bin/sql user/pass@delphix-1.test.com:1521:vd4

I want to run this but with a query included in a single line.

I tried just adding a space and the query after vdbsl4, but that did not work (I think it just gave me an error with instructions on how to use sqlcl).

How can I accomplish the connection + query in one line if at all possible?

Ben
  • 519
  • 1
  • 7
  • 14

2 Answers2

1

You can try STDin

`$sql barry/oracle << EOF
 select user from dual;
 EOF`

SQLcl: Release 12.2.0.1.0 RC on Mon Aug 08 18:29:09 2016

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Mon Aug 08 2016 18:29:10 +01:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

USER   

BARRY  


BARRY@orcl☘ >
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

and coming back again, you can echo it in to have a truely single line experience.

C:\TMP>echo select 1 from dual|\software\sqlcl\bin\sql barry/oracle@localhost:1521/xe

SQLcl: Release 17.2.0 Production on Tue Aug 29 18:13:40 2017

Copyright (c) 1982, 2017, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production



         1
----------
         1

SQL>

SQL>
Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

C:\TMP>
Barry McGillin
  • 465
  • 5
  • 11
0

Try

echo "SELECT 1 FROM DUAL" | sql usrnm/psw@myhost.com:1521:starter

P.D: For those using Service Name instead of SID remember to replace :starter by /ORCL (given the default installation values, otherwise replace them for your DB parameters obviously)

Ordiel
  • 2,442
  • 3
  • 36
  • 52