我试图在表中添加以下列,但它不断出现以下错误。 ORA-00933: SQL 命令未正确结束
更多详细信息:https://docs.oracle.com/error-help/db/ora-00933
我输入的代码是
INSERT INTO Customers (CustomerID, Customer_Last_Name, Customer_First_Name, Customer_Middle_Name, Suffix, Phone, Email_Address, First_Seen_Date, Customer_Address_Street1, Customer_Address_City, Customer_Address_State, Customer_Address_Zip, Customer_Address_Last_Modified_Date)
VALUES
(1, 'Roy', 'Casagranda', 'A', 'Jr', '1234567890', '[email protected]', ('2023-APR-15'), '777 Glades Rd', 'BocaRaton', 'FL', '33431', ('2023-APR-15')),
(2, 'Elon', 'Marley', 'A', 'Mr', '9876543210', '[email protected]', ('2023-APR-20'), '225 20th St', 'BocaRaton', 'FL', '33431', ('2023-APR-20')),
(3, 'Bill', 'Door', 'B', 'Mr', '5554443333', '[email protected]', ('2023-APR-10'), '3100 Lionshead St', 'BocaRaton', 'FL', '33431', ('2023-APR-10')),
(4, 'Mark', 'Musk', 'C', 'Jr', '2223334444', '[email protected]', ('2023-APR-05'), '1201 N Dixie Hwy', 'BocaRaton', 'FL', '33431', ('2023-APR-05')),
(5, 'Bill', 'Ackman', 'B', 'Sir', '1112223333', '[email protected]', ('2023-APR-15'), '555 Cedar St', 'BocaRaton', 'FL', '33431', ('2023-APR-15'));
我也尝试过使用 TO_DATE 函数,但它一直给我同样的错误。
Oracle 的表值构造函数
VALUES
在版本 23c 之前不支持多行。在 23c 版本以下,语句应该如下所示:
INSERT INTO Customers (CustomerID, Customer_Last_Name, Customer_First_Name, Customer_Middle_Name, Suffix, Phone, Email_Address, First_Seen_Date, Customer_Address_Street1, Customer_Address_City, Customer_Address_State, Customer_Address_Zip, Customer_Address_Last_Modified_Date)
SELECT 1, 'Roy', 'Casagranda', 'A', 'Jr', '1234567890', '[email protected]', date '2023-04-15', '777 Glades Rd', 'BocaRaton', 'FL', '33431', date '2023-04-15' FROM DUAL UNION ALL
SELECT 2, 'Elon', 'Marley', 'A', 'Mr', '9876543210', '[email protected]', date '2023-04-20', '225 20th St', 'BocaRaton', 'FL', '33431', date '2023-04-20') FROM DUAL UNION ALL
SELECT 3, 'Bill', 'Door', 'B', 'Mr', '5554443333', '[email protected]', date '2023-04-10', '3100 Lionshead St', 'BocaRaton', 'FL', '33431', date '2023-04-10' FROM DUAL UNION ALL
SELECT 4, 'Mark', 'Musk', 'C', 'Jr', '2223334444', '[email protected]', date '2023-04-05', '1201 N Dixie Hwy', 'BocaRaton', 'FL', '33431', date '2023-04-05' FROM DUAL UNION ALL
SELECT 5, 'Bill', 'Ackman', 'B', 'Sir', '1112223333', '[email protected]', date '2023-04-15', '555 Cedar St', 'BocaRaton', 'FL', '33431', date '2023-04-15' FROM DUAL;
如果上述格式不合适,您也可以使用
INSERT ALL
语法达到相同的结果。
我还将类似日期的字符串转换为日期文字。日期文字使用更标准的日期格式 YYY-MM-DD,而隐式转换为日期的字符串将使用会话(不可靠)默认日期格式。