此处不允许出现列 oracle

问题描述 投票:0回答:1

虽然我用双引号引起来的字符串,但我仍然收到“column not allowed here”错误。请帮助。预先感谢。

这是我的桌子:

CREATE TABLE mytable
(
  DATE_ID           DATE                        NOT NULL,
  DATE_NAME         VARCHAR2(10 BYTE),
  DATE_DATE         DATE,
  DAY_ID            NUMBER(1),
  YEAR_ID           NUMBER(4),
  QUARTER_ID        NUMBER(1),
  MONTH_ID          NUMBER(2),
  YEAR_MONTH_ID     NUMBER(6),
  WEEK_ID           NUMBER(2),
  YEAR_WEEK_ID      NUMBER(6),
  WEEKEND_FLAG      NUMBER(1),
  ETL_LOAD_TIME     TIMESTAMP(6),
  ETL_UPDATE_TIME   TIMESTAMP(6),
  SOURCE_SYSTEM_ID  NUMBER(5)
)

这是我程序的参数

    v_week NUMBER;
    v_day DATE;

cur_d 是我的光标,即

 for cur_d in 1..7

这是我的声明:

    v_query :='insert into mytable(date_id,date_name,date_date,day_id,year_id,quarter_id,month_id,year_month_id,week_id,year_week_id,weekend_flag,etl_load_time,etl_update_time,source_system_id) values 
    (v_day,to_char(v_day,''yy/mm/dd''),v_day,cur_d,to_number(to_char(v_day,''yyyy'')), to_number(to_char(v_day, ''Q'')) ,
    to_number(to_char(v_day, ''MM'')),to_number(to_char(v_day, ''YYYYMM'')) ,v_week,
    to_number(to_char(v_day,''iyyyiw'')),
    case when to_char(v_day,''DY'') in (''SAT'',''SUN'') then  1 else 0 end,sysdate ,sysdate ,10)';

这是程序

CREATE OR REPLACE PROCEDURE FILL_CAL_DATE(
v_start_day IN DATE
)
IS 
    v_week NUMBER;
    v_day DATE;
    v_query VARCHAR2(2000);
begin



v_week :=1;
SELECT TRUNC(v_start_day, 'iw')+(level-1)*7  into v_day from dual  connect by level <1;
dbms_output.put_line('*******');
dbms_output.put_line(v_day);
dbms_output.put_line('*******');
for cur_w in 1..572 --2045
loop

dbms_output.put_line(v_week);


if (mod (v_week,53)=0) then v_week:=1;
else v_week:=mod (v_week,53);end if;
dbms_output.put_line(v_week);
dbms_output.put_line('*******');

    for cur_d in 1..7
    loop
    v_query :='insert into mytable(date_id,date_name,date_date,day_id,year_id,quarter_id,month_id,year_month_id,week_id,year_week_id,weekend_flag,etl_load_time,etl_update_time,source_system_id) values 
    (v_day,to_char(v_day,''yy/mm/dd''),v_day,cur_d,to_number(to_char(v_day,''yyyy'')), to_number(to_char(v_day, ''Q'')) ,
    to_number(to_char(v_day, ''MM'')),to_number(to_char(v_day, ''YYYYMM'')) ,v_week,
    to_number(to_char(v_day,''iyyyiw'')),
    case when to_char(v_day,''DY'') in (''SAT'',''SUN'') then  1 else 0 end,sysdate ,sysdate ,10)';
    
   dbms_output.put_line(v_day|| '*' || to_char(v_day,'yy/mm/dd')|| '*'|| v_day || '*' || cur_d || '*'
    || to_number(to_char(v_day,'yyyy'))|| '*' ||  to_number(to_char(v_day, 'Q')) || '*' || 
    to_number(to_char(v_day, 'MM'))|| '*'||
    to_number(to_char(v_day, 'YYYYMM')) || '***' ||v_week || '*' ||
    to_number(to_char(v_day,'iyyyiw'))||'*'||
    case when to_char(v_day,'DY') in ('SAT','SUN') then  1 else 0 end || '*' ) ;
    
    dbms_output.put_line(v_query);

    v_day :=v_day+1;
   
    EXECUTE IMMEDIATE v_query;
    
end loop;
v_week := v_week+1;


end loop;
EXECUTE IMMEDIATE 'COMMIT;';

end  FILL_CAL_DATE;
/
oracle ora-00984
1个回答
0
投票

如果您想从另一列导出值,请使用虚拟列。

CREATE TABLE mytable
(
  DATE_ID           DATE                        NOT NULL,
  DATE_NAME         VARCHAR2(10 BYTE)
                    GENERATED ALWAYS AS (TO_CHAR(date_id, 'YY/MM/DD')),
  DATE_DATE         DATE
                    GENERATED ALWAYS AS (date_id),
  DAY_ID            NUMBER(1)
                    GENERATED ALWAYS AS (TRUNC(date_id) - TRUNC(date_id, 'IW') + 1),
  YEAR_ID           NUMBER(4)
                    GENERATED ALWAYS AS (EXTRACT(YEAR FROM date_id)),
  QUARTER_ID        NUMBER(1)
                    GENERATED ALWAYS AS (TO_NUMBER(TO_CHAR(date_id, 'Q'))),
  MONTH_ID          NUMBER(2)
                    GENERATED ALWAYS AS (EXTRACT(MONTH FROM date_id)),
  YEAR_MONTH_ID     NUMBER(6)
                    GENERATED ALWAYS AS (TO_NUMBER(TO_CHAR(date_id, 'YYYYMM'))),
  WEEK_ID           NUMBER(2)
                    GENERATED ALWAYS AS (TO_NUMBER(TO_CHAR(date_id, 'IW'))),
  YEAR_WEEK_ID      NUMBER(6)
                    GENERATED ALWAYS AS (TO_NUMBER(TO_CHAR(date_id, 'IYYYIW'))),
  WEEKEND_FLAG      NUMBER(1)
                    GENERATED ALWAYS AS (CASE WHEN date_id - TRUNC(date_id, 'IW') >= 5 THEN 1 ELSE 0 END),
  ETL_LOAD_TIME     TIMESTAMP(6),
  ETL_UPDATE_TIME   TIMESTAMP(6),
  SOURCE_SYSTEM_ID  NUMBER(5)
)
© www.soinside.com 2019 - 2024. All rights reserved.