Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ora-00918

Posted on 2008-10-19
4
441 Views
Last Modified: 2013-12-18
What could be the reason of this?

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> conn /as sysdba
Connected.
SQL> conn scott
Enter password: *****
Connected.
SQL> desc emp;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPNO                                     NOT NULL NUMBER(4)
 ENAME                                              VARCHAR2(10)
 JOB                                                VARCHAR2(9)
 MGR                                                NUMBER(4)
 HIREDATE                                           DATE
 SAL                                                NUMBER(7,2)
 COMM                                               NUMBER(7,2)
 DEPTNO                                             NUMBER(2)

SQL> desc bonus;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ENAME                                              VARCHAR2(10)
 JOB                                                VARCHAR2(9)
 SAL                                                NUMBER
 COMM                                               NUMBER

SQL> select empno,ename,job,mgr from emp,bonus;
select empno,ename,job,mgr from emp,bonus
                   *
ERROR at line 1:
ORA-00918: column ambiguously defined

0
Comment
Question by:dbaseek
4 Comments
 
LVL 3

Expert Comment

by:ddanonimity
ID: 22751560
if the job and job,bonus files contain the same values you could jsut get rid of the bonus at the end. If you want to get information which is unique to each table try doing the following

SELECT (<whatever> FROM <table1>) AND (SELECT <whatever> FROM <table 2>)

Not sure about the and though. may need diffrent syntax
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22751591
because ename and job,mgr in bothe the emp,bonus tables;

use alais to overcome this error.
select empno,e.ename,e.job,mgr from emp e
,bonus b
0
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22754009
This problem occurs because you have a column in both tables with the same name so the db is unable to determine which column you wanted.

So as chaituu says you an alias

What he is saying is change your select to include an alias name

in the FROM part of the clause to create an alias you would say FROM <tablename> aliasname, <tablename2> aliasname2

and in your SELECT part of the clause you would use those alias names.

So the code snippet below or above shows how this works.

Additionally, you could just qualify the field with the tablename itself rather than using an alias,

such as  SELECT EMP.EMPNO, EMP.ENAME, EMP.JOB, BONUS.MANAGER FROM EMP, BONUS;

The only time aliases are really needed is when you are doing a join on the same table but have the table included twice in the FROM clause and you need to distinguish between the two.

The other reason for using aliases is that it makes a kind of shorthand rather than typing out long tablenames all the time.



SELECT EMPNO, E.ENAME, E.JOB, MGR
FROM EMP E, BONUS B

Open in new window

0
 
LVL 4

Accepted Solution

by:
hqassap earned 500 total points
ID: 22755665
This is because empno exist in the two tables (emp,bonus); use an alias for the table to distinguish between empno of emp and empno of bonus:

SQL> select a.empno, a.ename, a.job,a.mgr from emp a,bonus b;

Also, this is a Cartesian (cross) product and you will get too many records duplicated (no. of empno records * no. of bonus records)
Use a join to get an accurate result:

SQL> select a.empno, a.ename, a.job,a.mgr from emp a,bonus b
where a.empno = b.empno;

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle sql query 7 74
oracle RMAN - trying to duplicate a database 5 39
Repeat query 13 61
join a table with user_tab_columns in oracle 3 48
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question