我在 oracle 中尝试 sql plus 中的一些问题,但它不起作用并且没有返回所需的结果。有人可以告诉我我做错了什么吗?
问题是:-
开发一个查询,该查询将识别并标记那些账单逾期超过 30 天的非活动客户(这通常可以使用子查询来完成)。请记住,您只是将客户标记为非活动状态,而不是实际从系统中删除客户记录。
这是我尝试过的查询:-
SELECT CUSTID, CUSTFIRSTNAME, CUSTSTATUS FROM CUSTOMER;
UPDATE CUSTOMER
SET CUSTSTATUS='I'
WHERE CUSTID IN
(SELECT CUSTID FROM BILLING
WHERE (SYSDATE - DUEDATE) > 30 AND PAIDDATE IS NULL);
SELECT CUSTID, CUSTFIRSTNAME, CUSTSTATUS FROM CUSTOMER;
计费表中的值如下:-
--INSERT STATEMENTS FOR TABLE BILLING
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(1, 1, 30, DATE '2012-07-01', 30, DATE '2012-07-01' );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(2, 2, 80, DATE '2012-06-25', 0, );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(3, 3, 50, DATE '2012-04-01', 0, );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(4, 4, 30, DATE '2012-06-11', 30, DATE '2012-06-11' );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(5, 5, 50, DATE '2012-04-30', 0, );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(6, 6, 80, DATE '2012-06-01', 80, DATE '2012-05-30' );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(7, 7, 30, DATE '2012-06-15', 0, );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(8, 8, 30, DATE '2012-05-30', 0, );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(9, 9, 80, DATE '2012-05-25', 0, );
INSERT INTO BILLING(CUSTID,BILLID,BILLAMT,DUEDATE,PAIDAMT,PAIDDATE )
VALUES(10, 10, 50, DATE '2012-04-01', 0, );
这些是 BILLING 和 Customer 表的结构:-
SQL> desc customer;
Name Null? Type
------------------------------------------------------------------------ -------- -----------------
CUSTID NOT NULL NUMBER(5)
CUSTSTATUS NOT NULL CHAR(1)
CUSTDELETERZN VARCHAR2(100)
CUSTDELETEDATE DATE
EMPID NOT NULL NUMBER(5)
CUSTFIRSTNAME NOT NULL VARCHAR2(30)
CUSTLASTNAME NOT NULL VARCHAR2(20)
CUSTSTARTDATE DATE
PACKID NOT NULL NUMBER(2)
CUSTPHONE VARCHAR2(12)
CUSTSTREET VARCHAR2(30)
CUSTCITY VARCHAR2(20)
CUSTSTATE CHAR(2)
CUSTZIP NUMBER(5)
CUSTEMAIL VARCHAR2(30)
SQL> desc billing;
Name Null? Type
------------------------------------------------------------------------ -------- -----------------
CUSTID NOT NULL NUMBER(5)
BILLID NOT NULL NUMBER(5)
BILLAMT NOT NULL NUMBER(5)
DUEDATE NOT NULL DATE
PAIDAMT NUMBER(5)
PAIDDATE DATE
我也试着写" WHERE (SYSDATE - DUEDATE) > 30 AND PAIDDATE ='');"
这也不起作用。
编辑:-
我现在在我的 INSERT 语句中插入了 NULL,现在我收到了这个错误:-
更新客户 * 第 1 行出现错误:ORA-02290:违反检查约束 (D03318785.CC_CUSTOMER_F_CUSTSTATUS)
有人可以帮忙吗?
创建客户表如下:-
CREATE TABLE CUSTOMER(
custid NUMBER(5) NOT NULL
CONSTRAINT pk_custid PRIMARY KEY,
custstatus CHAR(1) NOT NULL,
custdeleterzn VARCHAR2(100),
custdeletedate DATE,
empid NUMBER(5) NOT NULL,
custfirstname VARCHAR2(30) NOT NULL,
custlastname VARCHAR2(20) NOT NULL,
custstartdate DATE,
packid NUMBER(2) NOT NULL,
custphone VARCHAR2(12),
custstreet VARCHAR2(30),
custcity VARCHAR2(20),
custstate CHAR(2),
custzip NUMBER(5),
custemail VARCHAR2(30));