ORA-01748: 在 Oracle 中只允许简单的列名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47679564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:29:07  来源:igfitidea点击:

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

sqloracle

提问by Ahtisham

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 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

第 5 行的错误:ORA-01748:此处只允许简单的列名

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)
);

回答by Alex Poole

Your foreign key constraint syntaxis wrong; it should be:

您的外键约束语法错误;它应该是:

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.

您在 FK 列名前面加上了表名,这本身是错误的,但也有错误的地方。

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.

回答by Kaushik Nayak

According to oracle documentation,

根据oracle文档,

ORA ERR

错误

ORA-01748 only simple column names allowed here

ORA-01748 此处只允许简单的列名

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.

以下是此错误的原因:

此 SQL 语句不允许使用限定的列名,例如 username.table.column 或 table.column。

解决此问题可以采取的措施:从列中删除限定条件并重试该操作。

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

在您的情况下,您试图在定义约束时引用表名 -

Attendence.ST_ROLLNO- WRONG.

Attendence.ST_ROLLNO-错了

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

它必须包含一个没有表名或模式名的简单名称。