sql - PL/SQL 触发器 : can't create apex user

标签 sql database oracle plsql oracle-apex

我正在处理数据库,剩下的最后一项任务是创建用户帐户。出于某种原因,我似乎无法让它工作。事实上,没有注释的代码在取消注释时不起作用。我们主要关心的是能够自动创建用户帐户,而不是手动创建它们。我希望有人可以阐明我的方法中的错误,以便我的代码能够编译。

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/

相关文章:

java - 是否可以将 GROUP BY 与绑定(bind)变量一起使用?

sql - 使用 OUTPUT 子句插入不在 INSERTED 中的值

database - 将多个 id 存储到一个表列中是一种不好的做法吗

database - Grails 中的 Liquibase : “Empty result set, expected one row”

mysql - 在子查询中引用外部查询

oracle - 如何在db表中查找行创建日期和时间

sql - id对应另一列最大值的值

mysql - SQL:选择同一条道路上所有城镇的人口总和

sql - 甲骨文解码与 NVL

database - 选择、插入、删除时的事务隔离