sql - 尝试创建表时不断收到错误 ORA-02438
问题描述
我试图让我的代码运行,但它一直给我这个错误。我是 SQL 新手,还没有习惯它,我一直在尝试修复它,但我似乎无法让它工作。我已将这两个表放入下面的描述代码中。
Create table Account
(
Account_Number Number(7,0)
Constraint PK_Account_Account_Number Primary Key
Constraint NN_Account_Account_Number Not Null,
Account_Balance Number(13,2)
Constraint NN_Account_Account_Balance Not Null
);
Create table Investor
(
Investor_Number Number(7,0)
Constraint PK_Investor_Investor_Number Not Null,
First_Name Varchar2(25)
Constraint NN_Investor_First_Name Not Null,
Last_Name Varchar2(30)
Constraint NN_Investor_Last_Name Not Null,
Street_Address Varchar2(35)
Constraint NL_Investor_Street_Address Null,
City Varchar2(25)
Constraint NL_Investor_City Null,
Province Char(2)
Constraint CK_Investor_Province Check (Province in ('__'))
Constraint NL_Investor_Province Null,
Postal_Code Varchar2(7)
Constraint CK_Investor_Postal_Code Check (REGEXP_like(string,'[A-Z]-[0-9]-[A-Z]-[0-9]-[A-Z]-[0-9]'))
Constraint NL_Investor_Posta_Code Null,
Area_Code Number(3,0)
Default '780'
Constraint NN_Investor_Area_Code Not Null,
Phone_Number Number(7,0)
Constraint NN_Investor_Phone_Number Not Null,
Account_Number Number(7,0) Not Null,
Constraint FK__Investor_Account_Number --Name of Constraint
Foreign Key (Account_Number) -- Foreign Key Column name
References Account(Account_Number)-- name of table and column trying to reference,
);
解决方案
中的检查约束Postal_Code
是指string
而不是实际的列名;它应该是:
Postal_Code Varchar2(7)
Constraint CK_Investor_Postal_Code Check
(REGEXP_like(Postal_Code,'[A-Z]-[0-9]-[A-Z]-[0-9]-[A-Z]-[0-9]'))
Constraint NL_Investor_Postal_Code Null,
您得到的错误是因为解析器将其解释string
为标识符,并假设它是另一列的名称,即使它不是。但显然没有其他任何东西,所以这并非完全不合理。
推荐阅读
- c# - AvaloniaUI - 如何选择文件夹
- android - 如何使用内容类型 x-www-form-urlencoded android 改造发送发布请求
- java - 用对象覆盖Java中的equals方法
- java - Spring Boot 2 应用程序无法覆盖 RMIRegistry 默认端口 1099 以使 JMX 连接安全
- javascript - 在 React 中显示来自 API 的图像
- python - 使用 Axis 212 PTZ IP 摄像机和 openCV 在 Python 中打开视频流时遇到问题
- arrays - 我需要显示不带括号的信息
- primefaces - PrimeFaces 选择器,包括具有隐藏输入字段的组件的输入
- python - 在 Python 中初始化的条件类型
- mongodb - 如何在 MongoDB 中删除双嵌套数组中的元素