I am executing a SQL script which has spaces, semicolons, single-quotes, special characters etc. in of the column called prod_desc. I need to execute the script from SQLPLUS. I have the set the following in the SQLPLUS however, single quotes, semicolons are not taken into consideration.
set sqlblanklines on
See the below insert statement for instance, semicolon is after the line break. This is causing an error during execution. How can I resolve the issue?
SET DEFINE OFF;
Insert into PROD_DESC
(PROD_NO, PROD_DESC
)
Values
('XYZ', 'test
semicolon test;
'
);
Table Structure
CREATE TABLE prod_desc
(
prod_no VARCHAR2 (100),
prod_desc VARCHAR2 (1000)
);
Espace the semicolon:
SET DEF OFF;
Insert into PROD_DESC(PROD_NO, PROD_DESC)
Values('XYZ', 'test semicolon test\;');
I also like to use the q-quote syntax. It removes the need for escaping, and makes quoting quotes much easier.
The syntax is
q'[ <your string> ]'
<Your string>
can contain quotes or any other characters the normally need escaping. The [ can actually be substituted for or "paired" characters, such as {} or ().
For example:
SQL>
SQL> CREATE TABLE prod_desc
2 (
3 prod_no VARCHAR2 (10),
4 prod_desc VARCHAR2 (100)
5 );
Table created.
SQL>
SQL> SET DEFINE OFF;
SQL> Insert into PROD_DESC
2 (PROD_NO, PROD_DESC
3 )
4 Values
5 ('XYZ', q'[test
6 semicolon test
7 ; ]'
8 );
1 row created.
SQL>
SQL>
SQL> select * from prod_desc;
PROD_NO PROD_DESC
---------- ----------------------------------------------------------------------------------------------------
XYZ test
semicolon test
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With