Oracle

Cách để insert value ‘a & b’ vào varchar2 column (Oracle)

Cach 1:

Dung noi cac ky tu || hoặc # hoặc \

insert into table1 values('&'||'hello world');
hoặc insert into d1 values ('a#&b');
hoặc table1 values('a\&b');

1 row created. select * from table1; 
COL1 
-------------------------------------------------- 
&hello world
a&b

Cách 2:

Có thể dùng SET SCAN OFF hoặc SET DEFINE OFF.
Khuyến cáo nên dùng SET DEFINE OFF thay cho SET SCAN OFF

 SET DEFINE OFF;
 insert into test2(x) values('&hello world');

1 row created.

 commit;

Commit complete.
 select * from test2;

X
---------------------------------------

&hello world
http://docs.oracle.com/cd/E11882_01/server.112/e16604/apc.htm#SQPUG142

SET SCAN {ON|OFF} (obsolete)

Controls scanning for the presence of substitution variables and parameters. OFF suppresses processing of substitution variables and parameters; ON enables normal processing.

ON functions in the same manner as SET DEFINE ON.

Leave a comment