Thursday 7 May 2015

Ways of connection - sqlcl and the connect command

Where it looks for connections is a bit long winded:
Check -optl if this does not quite match what you are seeing.

Variables we support:
TNS_ADMIN (for finding tnsnames.ora)
LOCAL (windows=TWO_TASK)
TWO_TASK (non windows i.e. my database connection information e.g. tnsnames.ora entry name or EZCONNECT)
ORACLE_HOME (for finding tnsnames.ora)
SQLPATH (for finding login.sql)
PATH for finding .dll
LD_LIBRARY_PATH for finding .so
ORACLE_SID used in bequeath connection by thick oci driver.


tnsnames.ora - looks for tnsnames.* for example so might pick up an old setting in a .SAV file.

connect -oci username/password
nothing given:if currently connected try same utl different connection.
nothing given:not currently connected and -oci try bequeath

try TWO_TASK/LOCAL (if these are not null go to  'something given')
try localhost:1521/orcl
try 127.0.0.1:1521:$ORACLE_SID

if something given
try LDAPCON environment variable http://totierne.blogspot.in/2015/02/introducing-ldapcon-helper-feature-for.html
try tnsnames.ora
try NET xml store of connections http://totierne.blogspot.in/2015/04/net-command-persistently-store-network.html
try passing on to the driver untouched (could be (DESCRIPTION= or hostname resolution for example)
try hostname resolution ie @hostname or @hostname:1521/hostname (in case hostname=service name) (try with or without domain eg oracle.com - or domain got from looking up resolved host)
(if -oci try thick then try thin for each possibility (there are one or two that currently do not try thick))

On no connection give error output for each attempt. (optl shows what it is trying whether it connects or not).

If password is missing prompt for it, if connection fails and there was a prompt - prompt for everything up to 3 times.
At the username prompt: user@dbname is not currently supported.

SQLCL command line options

SQLCL options:

new:
-oci - try looking for 12.1.0.2 oci 'thick' c based library
-optl - turn on logging
-sshkey -sshhost I have not used these could be related to: http://barrymcgillin.blogspot.in/2015/05/sqlcl-cloud-connections-via-secure.html seems related.

From sqlplus
-h -help - show help page
-l -login - do not reprompts for user/password on failure
-R[estrict] 1 -R 2 -R 3 - restrict sqlcl for example R 3 - do not use @
-s[ilent] - suppress console output
-v - version
/nolog - do not log in
-nologin - do not read login.sql
@file.sql - run this file and come back if it does  not end in exit
username/password@connectionidentifier as sysdba|sysbackup|sysdg|syskm|sysasm|sysoper - login ([as role] is optional)

-optl shows you logging info:
where it looks for tnsnames.* and what urls it is trying
$ ./sql -optl notauser/notapassword@notanid

SQLcl: Release 4.1.0 Release Candidate on Thu May 07 14:34:11 2015

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


May 07, 2015 2:34:11 PM oracle.dbtools.raptor.utils.TNSHelper checkForTns
INFO: Checking for tnsnames.* in :/home/notauser
May 07, 2015 2:34:11 PM oracle.dbtools.raptor.utils.TNSHelper checkForTns
INFO: Checking for tnsnames.* in :/etc
May 07, 2015 2:34:11 PM oracle.dbtools.raptor.newscriptrunner.SQLPLUS logConnectionURL
INFO: Attempting to connect using URL= "jdbc:oracle:thin:@notanid"
May 07, 2015 2:34:11 PM oracle.dbtools.raptor.newscriptrunner.SQLPLUS logConnectionURL
INFO: Attempting to connect using URL= "jdbc:oracle:thin:@notanid:1521/notanid"
  USER          = notauser
  URL           = jdbc:oracle:thin:@notanid
  Error Message = IO Error: Unknown host specified
  USER          = notauser
  URL           = jdbc:oracle:thin:@notanid:1521/notanid
  Error Message = IO Error: Unknown host specified

Warning: You are no longer connected to ORACLE.

now try the thick driver: -oci (throws an error because I have  not got the .so  library in the path)
./sql -oci -optl notauser/notapassword@notanid

SQLcl: Release 4.1.0 Release Candidate on Thu May 07 14:36:10 2015

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


May 07, 2015 2:36:10 PM oracle.dbtools.raptor.utils.TNSHelper checkForTns
INFO: Checking for tnsnames.* in :/home/notauser
May 07, 2015 2:36:10 PM oracle.dbtools.raptor.utils.TNSHelper checkForTns
INFO: Checking for tnsnames.* in :/etc
May 07, 2015 2:36:10 PM oracle.dbtools.raptor.newscriptrunner.SQLPLUS logConnectionURL
INFO: Attempting to connect using URL= "jdbc:oracle:oci8:@notanid"
May 07, 2015 2:36:11 PM oracle.dbtools.raptor.newscriptrunner.SQLPLUS logConnectionURL
INFO: Attempting to connect using URL= "jdbc:oracle:thin:@notanid"
May 07, 2015 2:36:11 PM oracle.dbtools.raptor.newscriptrunner.SQLPLUS logConnectionURL
INFO: Attempting to connect using URL= "jdbc:oracle:thin:@notanid:1521/notanid"
  USER          = notauser
  URL           = jdbc:oracle:oci8:@notanid
  Error Message = no ocijdbc12 in java.library.path
  USER          = notauser
  URL           = jdbc:oracle:thin:@notanid
  Error Message = IO Error: Unknown host specified
  USER          = notauser
  URL           = jdbc:oracle:thin:@notanid:1521/notanid
  Error Message = IO Error: Unknown host specified

Warning: You are no longer connected to ORACLE.

Next post will be about how it attempts to connect.

Tuesday 5 May 2015

Pause prompt works per page:

bash-4.1$ bash sql scott/[the password]@[THE DATABASE}

SQLcl: Release 4.1.0 Release Candidate on Tue May 05 16:21:03 2015

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.x.x.x.x - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


SQL> set pause "Press any key to continue..."

SQL> set pause on

SQL> show pause
PAUSE is ON and set to "Press any key to continue..."

SQL> show pagesize
pagesize 24


SQL> select * from emp;

Press any key to continue...
     EMPNO ENAME      JOB              MGR HIREDATE
---------- ---------- --------- ---------- -------------------------------
       SAL       COMM     DEPTNO
---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80                      
       800                    20

      7499 ALLEN      SALESMAN        7698 20-FEB-81                      
      1600        300         30

      7521 WARD       SALESMAN        7698 22-FEB-81                      
      1250        500         30

      7566 JONES      MANAGER         7839 02-APR-81                      
      2975                    20

      7654 MARTIN     SALESMAN        7698 28-SEP-81                      
      1250       1400         30

      7698 BLAKE      MANAGER         7839 01-MAY-81                      
      2850                    30

      7782 CLARK      MANAGER         7839 09-JUN-81                      

Press any key to continue...
     EMPNO ENAME      JOB              MGR HIREDATE
---------- ---------- --------- ---------- -------------------------------
       SAL       COMM     DEPTNO
---------- ---------- ----------
      2450                    10

      7788 SCOTT      ANALYST         7566 19-APR-87                      
      3000                    20

      7839 KING       PRESIDENT            17-NOV-81                      
      5000                    10

      7844 TURNER     SALESMAN        7698 08-SEP-81                      
      1500          0         30

      7876 ADAMS      CLERK           7788 23-MAY-87                      
      1100                    20

      7900 JAMES      CLERK           7698 03-DEC-81                      
       950                    30

      7902 FORD       ANALYST         7566 03-DEC-81                      
      3000                    20

Press any key to continue...
     EMPNO ENAME      JOB              MGR HIREDATE
---------- ---------- --------- ---------- -------------------------------
       SAL       COMM     DEPTNO
---------- ---------- ----------
      7934 MILLER     CLERK           7782 23-JAN-82                      
      1300                    10


 14 rows selected


SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.x.x.x.x - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options