ORA-00904:“ NO_OF_PROJ_PER_CON_PY”:无效的标识符

时间:2018-11-19 21:19:07

标签: sql oracle

我正在尝试创建一个事实表,该表将显示每个顾问每年的项目数量。它有2个维度表,其中1个用于时间(report_time_dim),另一个用于顾问(consultant_dim),然后是主要事实表(fact_table)。

CREATE TABLE fact_table(
    fact_key INTEGER NOT NULL,
    consultant_key  INTEGER NOT NULL,
    time_key    INTEGER NOT NULL,
    no_of_projects_py   INTEGER,
    no_of_consultants_py    INTEGER,
    no_of_accounts_py   INTEGER,
    no_of_proj_per_con_py   INTEGER,
    fk1_time_key    INTEGER NOT NULL,
    fk2_consultant_key  INTEGER NOT NULL,
    -- Specify the PRIMARY KEY constraint for table "fact_table".
    -- This indicates which attribute(s) uniquely identify each row of data.
    CONSTRAINT  pk_fact_table PRIMARY KEY (consultant_key,time_key)
);

CREATE TABLE report_time_dim(
    time_key    INTEGER NOT NULL,
    year    INTEGER,
    -- Specify the PRIMARY KEY constraint for table "time_dim".
    -- This indicates which attribute(s) uniquely identify each row of data.
    CONSTRAINT  pk_report_time_dim PRIMARY KEY (time_key)
);

CREATE TABLE consultant_dim(
    consultant_key  INTEGER NOT NULL,
    project_id  INTEGER,
    consultant_id   INTEGER,
    -- Specify the PRIMARY KEY constraint for table "consultant_dim".
    -- This indicates which attribute(s) uniquely identify each row of data.
    CONSTRAINT  pk_consultant_dim PRIMARY KEY (consultant_key)
);

每个表都有它自己的代理键,我已经成功地填充了时间表和顾问表,但是事实表却存在我的问题。当我尝试填充它时,出现错误ORA-00904:“ NO_OF_PROJ_PER_CON_PY”:无效的标识符。我不确定如何解决此问题并填充事实表,以便它可以显示我想要的信息。任何帮助将不胜感激。

--populate fact_table

--table that lists consultant ids, project ids and years
DROP TABLE temp_fact1;
CREATE TABLE temp_fact1 AS 
SELECT project_id, fk2_consultant_id, to_number(to_char(lds_project.pj_actual_start_date, 'YYYY')) as which_year FROM lds_project;

--display table
SELECT * FROM temp_fact1;

--list that counts the number of projects for each consultant and specify the year
DROP TABLE temp_fact2;
CREATE TABLE temp_fact2 AS
SELECT which_year, fk2_consultant_id, COUNT(*) project_id FROM temp_fact1 GROUP by fk2_consultant_id, which_year;

--display table
SELECT * FROM temp_fact2;

--fact table surrogate key
DROP SEQUENCE fact_seq;
CREATE SEQUENCE fact_seq
START WITH 1
INCREMENT BY 1
MAXVALUE 1000000
MINVALUE 1
NOCACHE
NOCYCLE;

--load data

INSERT INTO fact_table (fact_key, consultant_key, time_key, no_of_proj_per_con_py) 
SELECT fact_seq.nextval, consultant_key, report_time_dim.time_key, no_of_proj_per_con_py FROM temp_fact2, report_time_dim WHERE temp_fact2.which_year = report_time_dim.year;

1 个答案:

答案 0 :(得分:0)

尝试单独运行此选择-这是脚本的最后一行。

SELECT fact_seq.nextval, 
       consultant_key, 
       report_time_dim.time_key, 
       no_of_proj_per_con_py 
FROM temp_fact2, report_time_dim 
WHERE temp_fact2.which_year = report_time_dim.year;

看起来TEMP_FACT2或REPORT_TIME_DIM都没有名为no_of_proj_per_con_py的列。我不确定您实际上要从哪里提取数据。