Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL*plus does not tokenize its command-line arguments properly when the program path contains spaces

I am using SQL*Plus with the following command line:

sqlplus user/pw@TNS @test.sql foo

The contents of test.sql follow:

SET VERIFY ON
DEFINE argone='&&1'
SELECT '&argone' FROM dual;
EXIT SQL.sqlcode

Results:

  • When SQL*Plus executable is in C:\Program Files\Oracle Client\whatever\sqlplus.exe then &&1 evaluates to Files\Oracle.
  • When SQL*Plus executable is in C:\Oracle\Client\10.2.xx\bin then &&1 evaluates to foo.

Did anyone encounter this problem and had a way to circumvent it?

like image 811
Benoit Avatar asked Sep 19 '11 12:09

Benoit


People also ask

Which is an SQL*Plus command?

SQL*Plus is a command-line tool that provides access to the Oracle RDBMS. SQL*Plus enables you to: Enter SQL*Plus commands to configure the SQL*Plus environment. Startup and shutdown an Oracle database.

Which of the following is buffered by SQL*Plus a SQL statements b SQL Plus commands C Pusql Block D none of these?

Tip. SQL*Plus buffers SQL statements and PL/SQL blocks, but not SQL*Plus commands. For example, the DESCRIBE command would not be buffered but a SELECT statement would be. To help make the distinction, think in terms of where the command is executed.

Which is the correct directory to place the executable file of execution type SQL*Plus in the server?

The SQL*Plus executable is usually installed in $ORACLE_HOME/bin, which is usually included in your operating system PATH environment variable. You may need to change directory to the $ORACLE_HOME/bin directory to start SQL*Plus.


1 Answers

You'll need to use double quotes at both the command line and the define statement to properly capture the arguments with spaces.

Script:

SET VERIFY ON
DEFINE argone="&&1"
SELECT '&argone' FROM dual;
EXIT SQL.sqlcode

Command line:

sqlplus user/pw@TNS @test.sql "foo bar"
like image 67
Allan Avatar answered Nov 15 '22 06:11

Allan