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.

Oracle

UNION ALLcommand is also to combine the results of two queries together, and UNION ALLselects all values.

The purpose of the SQL UNION ALLcommand is also to combine the results of two queries together. The difference between UNION ALL andUNION is that, while UNION only selects distinct values, UNION ALLselects all values.

Continue reading “UNION ALLcommand is also to combine the results of two queries together, and UNION ALLselects all values.”

Oracle

Union : combine the results of two queries together

The purpose of the SQL UNION query is to combine the results of two queries together. In this respect,UNION is somewhat similar to JOINin that they are both used to related information from multiple tables. One restriction of UNION is that all corresponding columns need to be of the same data type. Also, when using UNION, only distinct values are selected (similar to SELECTDISTINCT).

Continue reading “Union : combine the results of two queries together”

Oracle

MINUS : GET SUBTRACT FROM 2 STATEMENTS

The MINUS operates on two SQL statements. It takes all the results from the first SQL statement, and then subtract out the ones that are present in the second SQL statement to get the final answer. If the second SQL statement includes results not present in the first SQL statement, such results are ignored.

Continue reading “MINUS : GET SUBTRACT FROM 2 STATEMENTS”

Oracle

SQL to compare rows within two tables


SQL to compare rows within two tables

Oracle Tips by Burleson Consulting

Oracle Corporation’s developer Vadim Tropashko has some interesting notes on tuning Oracle SQL queries that compare the contents of two tables, showing several SQL solutions and their performance within the Oracle cost-based optimizer. 

Continue reading “SQL to compare rows within two tables”