Solved

ora-00918

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now