我正在处理数据库,剩下的最后一项任务是创建用户帐户。出于某种原因,我似乎无法让它工作。事实上,没有注释的代码在取消注释时不起作用。我们主要关心的是能够自动创建用户帐户,而不是手动创建它们。我希望有人可以阐明我的方法中的错误,以便我的代码能够编译。
create or replace TRIGGER trg_Students
BEFORE INSERT OR UPDATE OF SRN, Surname, Forename, Username, DOB, Date_Cv_Submitted, Date_cv_approved, same_address, home_phone_no, home_postcode ON Students
FOR EACH ROW
BEGIN
IF INSERTING THEN
:NEW.SRN := seq_SRN.nextval;
CREATE USER :new.USERNAME
IDENTIFIED BY PASSWORD
PROFILE app_user
PASSWORD EXPIRE;
--IF (ACTIVE_ACCOUNT = 'Y' AND CV_APPROVED = NULL) THEN
-- RAISE_APPLICATION_ERROR(-20000, 'Cannot create an account that is active before the cv is approved!');
--END IF;
END IF;
--IF UPDATING THEN
--IF (DATE_CV_APPROVED != NULL) THEN
--:new.Active_Account := 'Y';
--END IF;
--END IF;
:NEW.forename := INITCAP(:NEW.forename);
:NEW.surname := INITCAP(:NEW.surname);
:NEW.home_postcode := UPPER(:NEW.home_postcode);
:NEW.home_phone_no := REGEXP_REPLACE(:NEW.home_phone_no, '[^[:digit:]]', '');
:NEW.home_phone_no := REGEXP_REPLACE(:NEW.home_phone_no,
'([[:digit:]]{5})([[:digit:]]{6})', '(\1) \2');
IF :NEW.same_address = 'Y' THEN
:NEW.term_no := :NEW.home_no;
:NEW.term_postcode := :NEW.home_postcode;
:NEW.term_phone_no := :NEW.home_phone_no;
ELSE
:NEW.term_postcode := UPPER(:NEW.term_postcode);
:NEW.term_phone_no := REGEXP_REPLACE(:NEW.term_phone_no, '[^[:digit:]]', '');
:NEW.term_phone_no := REGEXP_REPLACE(:NEW.term_phone_no,
'([[:digit:]]{5})([[:digit:]]{6})', '(\1) \2');
END IF;
IF (:NEW.DOB + NUMTOYMINTERVAL(18,'YEAR') > SYSDATE) THEN
RAISE_APPLICATION_ERROR(-20000, 'Client must be at least 18 years of age!');
END IF;
IF (:NEW.Date_cv_approved < :NEW.date_cv_submitted) THEN
RAISE_APPLICATION_ERROR(-20000, 'Cannot approve a cv before it is submitted!');
END IF;
END;
错误是
Compilation failed, line 6 (13:19:44) The line numbers associated with compilation errors are relative to the first BEGIN statement. This only affects the compilation of database triggers. PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: ( begin case declare else elsif end exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge.
我已将我的方法更改为:
APEX_UTIL.CREATE_USER(
p_user_name => :new.USERNAME,
P_web_password => 'Password123');
现在它会产生这个错误:
An API call has been prohibited. Contact your administrator. Details about this incident are available via debug id "46046".
Contact your application administrator.
最佳答案
看起来很有趣,我正在回答我自己的问题,但我解决了这个问题。我用来创建 apex 用户的代码如下。
APEX_UTIL.CREATE_USER(
p_user_name => :new.USERNAME,
P_web_password => 'Password123',
p_change_password_on_first_use => 'Y');
通过从应用程序构建器中更改安全设置以允许 api 工作来解决上述错误,这是通过以下方式找到的。 Application Builder -> (Your Application) -> Shared Components -> Security Attributes 最后勾选页面底部运行时 API 使用旁边的框,我根据需要勾选了所有 3 个。
关于sql - PL/SQL 触发器 : can't create apex user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33567783/