Solved

ora-00918

Posted on 2008-10-19
4
442 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
[X]
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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

726 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