【问题标题】:Oracle APEX master detail page creation: ORA-06531 errorOracle APEX 主详细信息页面创建:ORA-06531 错误
【发布时间】:2021-10-27 09:41:11
【问题描述】:

我正在使用 APEX 使用以下 PL/SQL 方案创建一个群管理应用程序:

-- SHEEP table
create table sheep (
    sheep_id number(*,0) generated by default on null as identity,
    eid varchar2(6) not null,
    sex varchar2(6) not null,
    name varchar2(45),
    breed varchar2(255) not null,
    birth date,
    sheep_state varchar2(45) not null,
    lambs number(*,0) not null,
    lambs_sets number(*,0) not null,
    markings varchar2(4000),
    note varchar2(4000),
    constraint sheep_pk primary key (sheep_id)
);

-- EVENT table
create table event (
    event_id number(*,0) generated by default on null as identity,
    sheep_id varchar2(6) not null,
    name varchar2(255) not null,
    event_date date not null,
    description varchar2(4000) not null,
    location varchar2(45) not null,
    constraint event_pk primary key (event_id)
);

-- SALE table
create table sale (
    sale_id number(*,0) generated by default on null as identity,
    sheep_id varchar2(6) not null,
    price number(*,2) not null,
    sale_date date not null,
    location varchar2(45) not null,
    note varchar2(4000),
    constraint sale_pk primary key (sale_id)
);

在此方案中,SALEEVENT 表引用 SHEEP 表的 EID 字段(唯一5 个数字和一个字母的标识符 - 代表他们耳朵里的黄色标签)。我正在尝试创建一个 Master Detail 页面,它将绵羊与特定事件(绵羊发生了什么)和销售历史(如果它已售出、何时、何地、售价多少)联系起来.

我尝试同时使用创建应用程序向导创建页面向导,但每次都遇到同样的错误:

Ajax 调用返回服务器错误 ORA-06531:对执行 PL/SQL 代码的未初始化集合的引用。

它仍然可以让我在向导中继续,但是当我想选择详细信息表(SALE 和 EVENT)时,它们甚至不会出现在选择列表中(参见 here)。

有人有想法吗?我对 APEX 很陌生,我可能错过了一些东西。此外,如果您对我的关系方案有任何建议(做出改变,提高效率),也不要犹豫告诉我。

提前致谢!

【问题讨论】:

    标签: sql oracle plsql oracle-apex


    【解决方案1】:

    事件与绵羊之间或销售与绵羊之间没有关系。您声明 SALE 和 EVENT 表引用了 SHEEP 表的 EID 字段,但数据库不知道这一点,因为该关系尚未通过外键定义。表中的外键引用另一个表的主键,您不能引用另一列(如 EID),即使它是唯一的。

    在您的脚本中,在所有表中创建sheep_id NUMBER,并在SALE 和EVENT 中创建外键。像这样:

    -- SHEEP table
    create table sheep (
        sheep_id number(*,0) generated by default on null as identity,
        eid varchar2(6) not null,
        sex varchar2(6) not null,
        name varchar2(45),
        breed varchar2(255) not null,
        birth date,
        sheep_state varchar2(45) not null,
        lambs number(*,0) not null,
        lambs_sets number(*,0) not null,
        markings varchar2(4000),
        note varchar2(4000),
        constraint sheep_pk primary key (sheep_id)
    );
    
    -- EVENT table
    create table event (
        event_id number(*,0) generated by default on null as identity,
        sheep_id number not null,
        name varchar2(255) not null,
        event_date date not null,
        description varchar2(4000) not null,
        location varchar2(45) not null,
        constraint event_pk primary key (event_id),
        constraint fk_event_sheep
          foreign key (sheep_id)
          references sheep(sheep_id)
    );
    
    -- SALE table
    create table sale (
        sale_id number(*,0) generated by default on null as identity,
        sheep_id number not null,
        price number(*,2) not null,
        sale_date date not null,
        location varchar2(45) not null,
        note varchar2(4000),
        constraint sale_pk primary key (sale_id),
        constraint fk_sale_sheep
          foreign key (sheep_id)
          references sheep(sheep_id)    
    );
    

    这是在关系数据库系统中创建主从关系的方法,它应该允许您在 APEX 中创建主从表单。

    【讨论】:

    • 谢谢,我现在明白多了。我会尽快尝试的!
    • 乐于助人。请接受答案,在堆栈溢出中表示感谢的首选方式?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多