SQL - ORA-01748 - Only Simple Column Names Allowed Here in Oracle - Stack Overflow

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ORA-01748: only simple column names allowed here in Oracle

Asked 5 years, 11 months ago Modified 3 years, 1 month ago Viewed 28k times

What I am trying to do ?

I am trying to create two tables and at the same time i am trying to link them together using foreign and
3
primary keys. However I successfully create my parent table ( Student with primary key ) but failed to
create child table ( Attendence with foreign key ).

What is the problem ?

I get the following error while creating Attendence table:

ERROR at line 5: ORA-01748: only simple column names allowed here

My code:

Student table:

create table Student (

ST_ROLLNO NUMBER(6) constraint s_pk primary key,


ST_NAME VARCHAR(30) not null,
ST_ADDRESS varchar(35) not null
);

Attendence table:

create table Attendence (

ST_ROLLNO NUMBER(6),
ST_DATE VARCHAR(30) not null,
ST_PRESENT_ABSENT varchar(1) not null,
constraint f_pk Attendence.ST_ROLLNO foreign key references
Student(ST_ROLLNO)
);

sql oracle

Share Improve this question Follow edited Dec 6, 2017 at 17:11 asked Dec 6, 2017 at 16:55
Ahtisham
9,368 4 43 58

1 A column name is "simple" if it is not qualified with a table name. Constraints, at least in Oracle, cannot span across
tables; an out-of-line constraint, like you are defining, must be on a column (or combination of columns) in the
same table you are defining. So it makes no sense to qualify the name or names of the constrained column(s) with
the table name (which is understood); and the syntax prohibits it, to make it crystal clear. – user5683823 Dec 6, 2017
at 17:40
2 Answers Sorted by: Highest score (default)

Your foreign key constraint syntax is wrong; it should be:

5 constraint f_pk foreign key (ST_ROLLNO) references Student(ST_ROLLNO)

You are preceding the FK column name with the table name, which is wrong in itself, but also have it in
the wrong place.

create table Student (

ST_ROLLNO NUMBER(6) constraint s_pk primary key,


ST_NAME VARCHAR(30) not null,
ST_ADDRESS varchar(35) not null
);

Table STUDENT created.

create table Attendence (

ST_ROLLNO NUMBER(6),
ST_DATE VARCHAR(30) not null,
ST_PRESENT_ABSENT varchar(1) not null,
constraint f_pk foreign key (ST_ROLLNO) references Student(ST_ROLLNO)
);

Table ATTENDENCE created.

Share Improve this answer Follow edited Dec 6, 2017 at 18:08 answered Dec 6, 2017 at 16:58
Alex Poole
185k 11 181 321

Do you know how to perform DML operation on a table whoes column is type obeject ? – Ahtisham Dec 6, 2017 at
17:14

1 @Ahtisham - yes, but that doesn't have anything to do with this question. There are plenty of examples around,
depending on exactly what you're doing (including in the documentation), but if you try to follow those and can't
make it work then you'll need to ask a new question. – Alex Poole Dec 6, 2017 at 17:19

3 Or you can include the FK in the column definition and inherit the datatype: st_rollno constraint f_pk
references student(st_rollno) . – William Robertson Dec 6, 2017 at 17:32

@AlexPoole Change ST_PRESENT_ABSENT varchar(35) to ST_PRESENT_ABSENT varchar(1) I changed it in


question. – Ahtisham Dec 6, 2017 at 17:57

1 @Ahtisham - that's irrelevant to the issue you were having, and won't ever help anyone else.. but OK... Changing the
question after it's been answered is pointless anyway though (or even rude for more substantial changes than this).
– Alex Poole Dec 6, 2017 at 18:09

According to oracle documentation,

ORA ERR
5
ORA-01748 only simple column names allowed here

The following is the cause of this error:


This SQL statement does not allow a qualified column name, such as username.table.column or
table.column.

Action you can take to resolve this issue: Remove the qualifications from the column and retry
the operation.

In your case, you are trying to refer to the table name while defining a constraint -

Attendence.ST_ROLLNO - WRONG.

It must contain a simple name without the table name or schema name.

Share Improve this answer Follow answered Dec 6, 2017 at 17:11


Kaushik Nayak
30.9k 6 32 45

Sir do you know how to perform DML operation on a table whoes column is type obeject ? – Ahtisham Dec 6,
2017 at 17:15

1 @Ahtisham : It is too broad question and not in the scope of a comment section of an unrelated answer. You may
google it or ask that as a separate question providing the details. And you don't have to address me as "Sir" the next
time. – Kaushik Nayak Dec 6, 2017 at 17:19

You might also like