如何在 oracle 11g 中使用内连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12420097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:06:34  来源:igfitidea点击:

How to use inner join in oracle 11g?

sqloraclejoininner-join

提问by Vikash

I am running my Oracle query here but it's not working but the same query is working in SQL Server

我在这里运行我的 Oracle 查询,但它不起作用,但同样的查询在 SQL Server 中运行

Here is my query:

这是我的查询:

SELECT d.dept_code,
       d.dept_name,
       d.dept_desc,
       e.comp_name
FROM   dept_master d
       inner join comp_master e
               ON d.comp_id = e.comp_id 

where in dept_master.comp_idvalue is the same as in Dept_Mastertable.

其中dept_master.comp_id值与Dept_Master表中相同。

回答by dejjub-AIS

The reason you are not getting any result is mainly because of the data

你没有得到任何结果的原因主要是因为数据

do this check to see if data is available in the tables

执行此检查以查看表中是否有数据可用

select * from dept_master;
select * from comp_master;

and see if both tables have any matching rows, i.e.; at least 1 row has same comp_id in both tables

并查看两个表是否有任何匹配的行,即;两个表中至少有 1 行具有相同的 comp_id

I hope you will find the answer after doing this exercise

我希望你在做完这个练习后会找到答案

回答by Geordee Naliyath

Is comp_id a character field? In that case define it as VARCHAR2 in Oracle. or try trim(d.comp_id) = trim(e.comp_id)

comp_id 是字符字段吗?在这种情况下,在 Oracle 中将其定义为 VARCHAR2。或尝试修剪(d.comp_id)=修剪(e.comp_id)

See a demonstration in SQL Fiddle.

请参阅SQL Fiddle 中演示