EZconnect for SQL*Plus

Posted by

Just a quick tip to solve a common issue that is catching people out.

The EZconnect syntax is a great way of connecting to the database without all the rigmarole of setting up and maintaining a tnsnames.ora file. You just nominate the host, service, and optionally the port and away you go.


SQL> connect scott/tiger@//localhost:1519/pdb1
Connected.

Of course, we don’t want to be providing the password on the command line so what happens in SQL*Plus when we leave it out?


SQL> connect scott@//localhost:1519/pdb1
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM|SYSRAC}] [edition=value]]
where  ::= [/][@]
       ::= [][/][@]

There’s an easy fix though. Just add some quotes and you’re good to go!


SQL> connect scott@'//localhost:1519/pdb1'
Enter password: ******
Connected.

This seems to be a SQL*Plus oddity. SQLcl handles this just fine.


SQL> show version
Oracle SQLDeveloper Command-Line (SQLcl) version: 21.2.2.0 build: 21.2.2.223.0914
SQL> connect scott@//localhost:1519/pdb1
Password? (**********?) *****
Connected.

Enjoy!

Got some thoughts? Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.