Oracle connection tests and Oracle connection tests

Source: Internet
Author: User

Oracle connection tests and Oracle connection tests

For more in-depth left outer join, we did some tests. There are several forms of external join writing. We can track the final SQL conversion form through 10053.

-- Initialize data

Create table

(
Id number,
Age number
);
Create table B
(
Id number,
Age number
);
Insert into A values (1, 10 );
Insert into A values (2, 20 );
Insert into A values (3, 30 );
Insert into B values (1, 10 );
Insert into B values (2, 20 );
Commit;


-- Use 10053 to find the final converted SQL

Alter session set session_cached_cursors = 0;
Alter session set events '10053 trace name context forever, level 1 ';
Explain plan for select * from A left join B on A. id = B. id and A. age> 5;
Explain plan for select * from A left join B on A. id = B. id WHERE A. age> 5;
Explain plan for select * from A left join B on A. id = B. id and B. age> 5;
Explain plan for select * from A left join B on A. id = B. id where B. age> 5;
Alter session set events '10053 trace name context off ';


Select * from A left join B on A. id = B. id and A. age> 5;
ID AGE
----------------------------------------
1 10 1 10
2 20 2 20
3 30
-- Final query after transformations:
SELECT "". "ID" "ID", "". "AGE" "AGE", "B ". "ID" "ID", "B ". "AGE" "AGE"
FROM "GG_TEST". "A" "A", "GG_TEST". "B" "B"
WHERE "A". "ID" = "B". "ID" (+)
AND "A". "AGE"> case when ("B". "ID" (+) IS NOT NULL) THEN 5 ELSE 5 END


Select * from A left join B on A. id = B. id WHERE A. age> 5;
ID AGE
----------------------------------------
1 10 1 10
2 20 2 20
3 30
-- Final query after transformations:
SELECT "". "ID" "ID", "". "AGE" "AGE", "B ". "ID" "ID", "B ". "AGE" "AGE"
FROM "GG_TEST". "A" "A", "GG_TEST". "B" "B"
WHERE "A". "AGE"> 5
AND "A". "ID" = "B". "ID" (+ );


Select * from A left join B on A. id = B. id and B. age> 5;
ID AGE
----------------------------------------
1 10 1 10
2 20 2 20
3 30
-- Final query after transformations:
SELECT "". "ID" "ID", "". "AGE" "AGE", "B ". "ID" "ID", "B ". "AGE" "AGE"
FROM "GG_TEST". "A" "A", "GG_TEST". "B" "B"
WHERE "A". "ID" = "B". "ID" (+)
AND "B". "AGE" (+)> 5

-- In this form, you can see that the external connection is invalid, and CBO is still very smart.
Select * from A left join B on A. id = B. id where B. age> 5;

ID AGE
----------------------------------------
1 10 1 10
2 20 2 20
-- Final query after transformations:
SELECT "". "ID" "ID", "". "AGE" "AGE", "B ". "ID" "ID", "B ". "AGE" "AGE"
FROM "GG_TEST". "A" "A", "GG_TEST". "B" "B"
WHERE "B". "AGE"> 5
AND "A". "ID" = "B". "ID ";


What is the left connection and connection of oracle?

This is the primary and secondary tables. When the two tables match, the primary table is used as the primary table. Go to Baidu for a tutorial.
 
What are the differences between left and right connections in ORACLE and left and right outer connections?

The left join is the same as the left Outer Join. Left join = left outer join.
T. TABLE_ID = TT. TABLE_ID (+) is equivalent to left join.
The left link displays no data corresponding to the right link.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.