Solved

ora-00918

Posted on 2008-10-19
4
444 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…
Via a live example, show how to take different types of Oracle backups using RMAN.

695 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