在 Oracle SQL 开发人员中是否有可能做这样的事情
CREATE FUNCTION fnCheckValid(accountidd IN NUMBER)
RETURN NUMBER
IS retval NUMBER(4,0);
BEGIN
SELECT COUNT(accountid_fk)
INTO retval
FROM tbl_AccountAuthentications
WHERE accountid_fk = accountidd;
RETURN(retval);
END;
/
ALTER TABLE tbl_AccountAuthentications
ADD CONSTRAINT chkCheckvalid CHECK(fnCheckValid(accountid_fk) <= 1);
我不断得到的错误是
Error starting at line 999 in command:
ALTER TABLE tbl_AccountAuthentications
ADD CONSTRAINT chkCheckvalid CHECK(fnCheckValid(accountid_fk) <= 1)
Error report:
SQL Error: ORA-00904: "FNCHECKVALID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
该函数正在创建中,我可以找到它,但是当我尝试调用它时,我不断收到该错误
这就是我想要实现的目标
AccountID RegularID OpenID
1 5 null
1 null 10
1 null 11
1 6 <-- Forbidden
这样用户就不能创建 2 个常规帐户,但可以拥有任意数量的 OpenID 帐户
表设置如下
CREATE TABLE tbl_AccountAuthentications(
newAuthID NUMBER(4,0)
CONSTRAINT naid_pk PRIMARY KEY,
accountid_fk NUMBER(4,0)
CONSTRAINT accid_fk
REFERENCES tbl_UserAccounts(account_id),
regularid_fk NUMBER(4,0)
CONSTRAINT rgid_fk
REFERENCES tbl_StrongRoom(password_id),
openid_fk NUMBER(4,0)
CONSTRAINT opid_fk
REFERENCES tbl_OpenID(openid)
);