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

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

November 9, 2012 Leave a comment Go to comments

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.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: