Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ora-00918

Posted on 2008-10-19
4
Medium Priority
?
453 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

564 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