如何防止SQLPlus修剪尾随空格

时间:2017-11-24 07:31:20

标签: oracle sqlplus

如果我在SQLPlus中执行以下脚本:

CREATE TABLE trailing_spaces (text VARCHAR2(100))
/

-- Note that there is a blank space after 'one' and 'two'
INSERT INTO trailing_spaces (text) VALUES ('one 
two 
three')
/

COMMIT
/

SQLPlus自动修剪线条并删除尾随空格,因此插入one two three而不是插入值onetwothree

有谁知道如何防止SQLPlus修剪这些行并按原样执行脚本?

2 个答案:

答案 0 :(得分:0)

您可以像SQLPLUS

那样执行此操作
SQL> CREATE   TABLE trailing_spaces (text VARCHAR2(100));

Table created.

SQL> INSERT INTO trailing_spaces (text) VALUES ('one'||'  '||
                                           'two'||'  '||
                                           'three')  ;

1 row created.

SQL> COMMIT;

Commit complete.

SQL> SELECT * FROM TRAILING_SPACES;

TEXT
--------------------------------------------------------------------------------
one  two  three

答案 1 :(得分:0)

如果我执行你的insert语句,我会在三个不同的行上得到文本。你怎么能把文字作为onetwothree一行得到?我正在使用Oracle 11.2.0.4

在我的情况下,如果我无法改变脚本,我可以运行现有脚本并在选择期间对其进行操作,如下所示。

SQL> insert into tbl1 values('one
  2   two');

1 row created.

SQL> insert into tbl1 values('three
  2   four');

1 row created.

SQL> select * from tbl1;

TEXT
--------------------
one
 two

three
 four



SQL> select REPLACE(REPLACE(text, CHR(10)), CHR(13)) as text from tbl1;

TEXT
--------------------
one two
three four