我有一个简单的更新程序。因此,我希望更新仅字段,而不是空值。我该怎么办?
PROCEDURE UpdateCustomerInfo(
CustomerID IN NUMBER,
CustomerType IN VARCHAR2,
CustomerName IN VARCHAR2,
CustomerGender IN VARCHAR2,
CustomerBirthday IN DATE)
AS
BEGIN
UPDATE CUSTOMER_INFO
SET CUSTOMER_TYPE =CustomerType,
CUSTOMER_NAME =CustomerName,
CUSTOMER_GENDER =CustomerGender,
CUSTOMER_BIRTHDAY =CustomerBirthday
WHERE CUSTOMER_ID = CustomerID;
COMMIT;
END CUSTOMER_INFO
任何人都可以帮助我?
由于
答案 0 :(得分:4)
UPDATE CUSTOMER_INFO
SET CUSTOMER_TYPE = NVL(CustomerType, CUSTOMER_TYPE),
CUSTOMER_NAME = NVL(CustomerName, CUSTOMER_NAME),
CUSTOMER_GENDER = NVL(CustomerGender, CUSTOMER_GENDER),
CUSTOMER_BIRTHDAY = NVL(CustomerBirthday, CUSTOMER_BIRTHDAY)
WHERE CUSTOMER_ID = CustomerID;
应该这样做。如果第一个参数是NVL
,NULL
函数将返回第二个参数。因此,如果CustomerType
参数为NULL
,则CUSTOMER_TYPE
列将更新为具有已有的值。您仍然在进行更新(例如生成重做),但您并未更改数据。