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 ......
ºÜ¶àÅóÓÑÒªÎÒ°ïæÍƼöÒ»ÏÂOracleµÄÈëÃÅÊé¼®£¬Äܹ»Á˽âOracleµÄ»ù±¾¸ÅÄî¡¢»ù±¾ÖªÊ¶µÄÄÇÖÖ¡£
ÎÒ¾ÍÃâΪÆäÄÑ£¬ÍƼö¼¸±¾¡£
Ê×ÏÈÎÒÏëÇ¿µ÷µÄÒ»µãÊÇ£¬ÈκÎÒ»±¾ÏµÍ³µÄOracleÊé¼®Ö»ÒªÈÏÕæ¶ÁÏÂÀ´£¬¶¼»áÓв»´íµÄÊÕ»ñ£¬¶ÁÊé×î¼É»äµÄÊÇ»¢Í·Éßβ£¬Ç³³¢ÔòÖ¹¡£
1.µÚÒ»±¾ÒªÍƼö¸ø´ó¼ÒµÄÊÇOracleµÄ¸ÅÄîÊֲᣬÕâ±¾ÊÖ²áÊÇÎÞÊýDBAѧϰµÄÆðµã£ ......
ÄãÊÇ·ñΪµÈ´ýÄãµÄ²éѯ·µ»Ø½á¹û¶ø¸Ðµ½Æ£±¹£¿ÄãÊÇ·ñÒѾΪÔöÇ¿Ë÷ÒýºÍµ÷ÓÅSQL¶ø¸Ðµ½Æ£±¹£¬µ«ÈÔÈ»²»ÄÜÌá¸ß²éѯÐÔÄÜ£¿ÄÇô£¬ÄãÊÇ·ñÒѾ¿¼ÂÇ´´½¨ÎﻯÊÓͼ£¿ÓÐÁËÎﻯÊÓͼ£¬ÄÇЩ¹ýÈ¥ÐèÒªÊýСʱÔËÐеı¨¸æ¿ÉÒÔÔÚ¼¸·ÖÖÓÄÚÍê³É¡£ÎﻯÊÓͼ¿ÉÒÔ°üÀ¨Áª½Ó£¨join£©ºÍ¼¯ºÏ£¨aggregate£©
ÄãÊÇ·ñΪµÈ´ýÄãµÄ²éѯ·µ»Ø½á¹û¶ø¸Ðµ½Æ£±¹£¿ÄãÊÇ·ñÒÑ ......
Êø£¬Ë÷Òý
1¡¢²éÕÒ±íµÄËùÓÐË÷Òý£¨°üÀ¨Ë÷ÒýÃû£¬ÀàÐÍ£¬¹¹³ÉÁУ©£º
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name = i.table_name and t.table_name = Òª²éѯµÄ±í
2¡¢²éÕÒ±íµÄÖ÷¼ü£¨°üÀ¨Ãû³Æ£¬¹¹³ÉÁУ©£º
select cu.* from user_cons_columns cu ......
¶ÔÏó³Ö¾Ã»¯£¬Ò²¾ÍÊÇ¿ÉÒÔ°ÑÕâ¸ö¶ÔÏóÓÀÔ¶µÄ±£´æÆðÀ´£¬ÕâÀïµÄ±£´æ²»½öÊǶÔÏó±¾Éí£¬»¹°üÀ¨ËûµÄÊôÐÔºÍËùÒÀÀµµÄÆäËûÀࡣͨ³££¬¶ÔÏó¿ÉÒԳ־û¯µ½Îļþ»òÕßÊÇÊý¾Ý¿âÖС£ÎÒÕâÀïÖ»½éÉÜÈçºÎ½«¶ÔÏó´æ´¢µ½Êý¾Ý¿âÖС£Ç¡ÇÉOracleÊý¾Ý¿âΪÎÒÃÇÌṩÁËÕâÑùµÄ·½±ã¡£
ÔÚOracleÖУ¬ÓÐÒ»ÖÖblogµÄ×Ö¶ÎÀàÐÍ£¬ËüÊÇÓÃÀ´´æ´¢´óÁ¿µÄ¶ ......