我有一個從查詢創建的視圖。該查詢從兩個連接在一起的表中檢索數據。其中一個使用主鍵進行內部連接。但數據在主鍵上返回空結果。這裏有什麼問題?Oracle從主鍵列中選擇返回空值?
CREATE TABLE orderinfo
(
orderid VARCHAR2 (20),
qtty NUMBER (20, 0),
price NUMBER (20, 0)
)
/
ALTER TABLE orderinfo ADD CONSTRAINT orderinfo_pk PRIMARY KEY (orderid)
/
INSERT INTO orderinfo (orderid, qtty, price)
VALUES ('OD00001', 1000, 15000);
INSERT INTO orderinfo (orderid, qtty, price)
VALUES ('OD00002', 2000, 15000);
INSERT INTO orderinfo (orderid, qtty, price)
VALUES ('OD00003', 3000, 15000);
INSERT INTO orderinfo (orderid, qtty, price)
VALUES ('OD00004', 4000, 15000);
COMMIT
/
create table ordersend
(
orderid varchar2(20),
orderstatus varchar2(3)
)
ALTER TABLE ordersend ADD CONSTRAINT ordersend_pk PRIMARY KEY (orderid)
/
INSERT INTO ordersend (orderid, status)
VALUES ('OD00001', 'N');
INSERT INTO ordersend (orderid, status)
VALUES ('OD00002', 'N');
INSERT INTO ordersend (orderid, status)
VALUES ('OD00003', 'N');
INSERT INTO ordersend (orderid, status)
VALUES ('OD00004', 'N');
COMMIT
/
CREATE VIEW vw_ordersendstatus
AS
SELECT "orderid",
"qtty",
"price",
"status"
FROM (SELECT inf.orderid,
inf.qtty,
inf.price,
send.status
FROM orderinfo inf, ordersend send
WHERE inf.orderid = send.orderid AND status = 'N')
/
CREATE TABLE orderblock
(
orderid VARCHAR2 (20),
qtty NUMBER (20, 0),
price NUMBER (20, 0)
)
/
CREATE PROCEDURE pr_sendorder
IS
CURSOR c_send
IS
SELECT orderid orderid,
qtty,
price,
status
FROM vw_ordersendstatus;
BEGIN
FOR i IN c_send
LOOP
INSERT INTO orderblock (orderid, qtty, price)
VALUES (i.orderid, i.qtty, i.price);
UPDATE ordersend
SET status = 'B'
WHERE orderid = i.orderid;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
RAISE '-1';
END;
然後 SELECT * FROM orderblock
返回上OrderID字段
爲什麼空值??? 請幫助
您的視圖不能成功編譯,因爲你在'select'使用區分大小寫的標識符的當子查詢不使用這些標識符。因爲沒有'status'列,所以'insert'語句到'ordersend'失敗。 – 2014-08-28 03:47:44