How do I ignore ampersands in a SQL script running from SQL Plus?
This may work for you:
set define off
Otherwise the ampersand needs to be at the end of a string,
'StackOverflow &' || ' you'
EDIT: I was click-happy when saving... This was referenced from a blog.
Escaping ampersand character in SQL string
Instead of
node_name = 'Geometric Vectors \& Matrices'
use
node_name = 'Geometric Vectors ' || chr(38) || ' Matrices'
38 is the ascii code for ampersand, and in this form it will be interpreted as a string, nothing else. I tried it and it worked.
Another way could be using LIKE and an underline instead the '&' character:
node_name LIKE 'Geometric Vectors _ Matrices'
The chance that you'll find some other record too, which is different in only this one character, is quite low.
How to escape ampersand in TOAD?
Try putting set define off
at the beginning of your script. It should work with F5:
set define off;
insert into x values('hello & world');
set define on;
Oracle SQL escape character (for a '&')
the &
is the default value for DEFINE
, which allows you to use substitution variables. I like to turn it off using
SET DEFINE OFF
then you won't have to worry about escaping or CHR(38).
Arguments passed to SQL*Plus script override the arguments of script which invoked it
You can save the original argument in a new variable:
file1.sql:
prompt Argument 1 = &1
define somevar = &1
@file2.sql col2 col1
prompt Original argument 1 = &somevar
Output:
SQL> @file1.sql col1
Argument 1 = col1
This is file2.sql
Original argument 1 = col1
Can I stop SQL*Plus from displaying connected when I have a connect in a script?
Here's a tip I've used from Tom Kyte's book (forget which one). I have a script called connect.sql in my sqlplus directory:
set termout off
connect &1
@login
and in my glogin.sql I've added this:
select lower(user) || '@' ||
substr( global_name,1, decode( dot, 0, length(global_name), dot-1) )
global_name
from (select global_name, instr(global_name,'.') dot from global_name );
set sqlprompt '&gname> '
set termout on
then I call
@connect user_01/pass_01@db_01
instead of
connect user_01/pass_01@db_01
Related Topics
MySQL Query Finding Values in a Comma Separated String
How to Delete Duplicate Rows in SQL Server
Optimal Way to Concatenate/Aggregate Strings
How to See What Character Set a MySQL Database/Table/Column Is
How to Use Returning With on Conflict in Postgresql
How to Do the Recursive Select Query in MySQL
Aggregate Columns With Additional (Distinct) Filters
MySQL - Get Row Number on Select
Using Group by on Multiple Columns
Count Work Days Between Two Dates
How to Select the Newest Four Items Per Category
How to Update If Exists, Insert If Not (Aka "Upsert" or "Merge") in MySQL
How to Access the "Previous Row" Value in a Select Statement
Datetime2 VS Datetime in SQL Server
MySQL Fails On: MySQL "Error 1524 (Hy000): Plugin 'Auth_Socket' Is Not Loaded"
Gem Install: Failed to Build Gem Native Extension (Can't Find Header Files)