Oracle左右全连接总结
--建立测试数据
create table a(id number);
create table b(id number);
insert into a values(1);
insert into a values(2);
insert into a values(3);
insert into b values(1);
insert into b values(2);
insert into b values(4);
commit;
--左:
--主流数据库通用的方法
select * from a left join b on a.id=b.id;
--Oracle特有的方法
select * from a, b where a.id=b.id(+);
ID ID
---------- ----------
1 1
2 2
3
--右:
--主流数据库通用的方法
select * from a right join b on a.id=b.id;
--Oracle特有的方法
select * from a, b where a.id(+)=b.id;
ID ID
---------- ----------
1 1
2 2
4
--内
--主流数据库通用的方法
select * from a join b on a.id=b.id;
--where关联
select * from a, b where a.id=b.id;
ID ID
---------- ----------
1 1
2 2
--全外
--主流数据库通用的方法
select * from a full join b on a.id=b.id;
--Oracle特有的方法
select *
from a, b
where a.id = b.id(+)
union
select *
from a, b
where a.id(+) = b.id;
ID ID
---------- ----------
1 1
2 2
3
4
--完全,也叫交叉连接或者笛卡尔积
--主流数据库通用的方法
select * from a,b;
--或者
select * from a cross join b;
ID ID
---------- ----------
1 1
1 2
1 4
2 1
2 2
2 4
3 1
3 2
3 4
连接无非是这几个
--内连接和where相同
inner join
--左向外连接,返回左边表所有符合条件的
left join
--右向外连接,返回右边表所有符合条件的
right join
--完整外部连接,左向外连接和右向外连接的合集
full join
--交叉连接,也称笛卡儿积。返回左表中的每一行与右表中所有行的组合
cross join
--补充:
--左向外连接,返回左边表所有符合条件的,
--注意这里没有第二个加号,会直接过滤掉数据,只显示符合条件的记录
select *
from a, b
where a.id = b.id(+)
and b.id = 2;
ID ID
---------- ----------
2 2
--左向外连接,返回左边表所有符合条件的
--注意where上第二个加号,它的作用是修改右边表记录的显示,例如如果b.id(+) = 2,显示为2,否则显示null
select *
from a, b
where a.id = b.id(+)
and b.id(+) = 2;
ID ID
---------- --
相关文档:
/**
* 更新记录,原子操作,不会commit
* @param sql_id
* @param condition
* @return
* @throws SQLException
*/
&nbs ......
decode()函數使用技巧
·软件环境:
1、Windows NT4.0+ORACLE 8.0.4
2、ORACLE安装路径为:C:\ORANT
·含义解释:
decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)
该函数的含义如下:
IF 条件=值1 THEN
RETURN(翻译值1)
ELSIF 条件=值2 THEN
RETURN(翻译值2)
......
分页查询格式:
SELECT * from
(
SELECT A.*, ROWNUM RN
from (SELECT * from TABLE_NAME) A
WHERE ROWNUM <= 40
)
WHERE RN >= 21
其中最内层的查询SELECT * from TABLE_NAME表示不进行翻页的原始查询语句。ROWNUM <= 40和RN >= 21控制分页查询的每页的范围。
上面给出的这个分页查询语句,在大多 ......
首先搞清下几个概念:
ORACLE中,约束分deferred 跟 immediate 2种:
deferred:如果 Oracle 在事务提交(commit)时才对约束执行检查,则称此约束是延迟的(deferred)。如果数据违反了延迟约束,提交操作将导致事务被回滚(undo)。
immediate:如果约束是即时的(immediate)(非延迟的),则此约束将在 ......
我用的是Centos5.4 DVD光盘安装的linux操作系统,安装linux的时候选上开发工具,Xmanager,与数据库相关的包。
操作系统安装完成之后需要进行一系列的配置才能安装oracle10g,下面把主要步骤记录下来。
1.安装完操作系统之后还是有些包没有安装,然而安装oracle10g的时候需要用到,没有安装的包有:
libXp-1.0.0-8.i386.rp ......