我正在尝试运行此代码
declare
temp_atr_val varchar2(400);
temp_val varchar2 (400);
temp_sum_percent decimal (10,3);
temp_variable number (10,3);
column_count number ;
val_count number;
sales_store number;
begin
select count(distinct ATTRIBUTE_INPUT) into column_count from look_up_table;
for ind in 1..column_count loop
/* putting current value of attribute from look_up_table in temp variable*/
select ATTRIBUTE_INPUT into temp_atr_val from (
select ATTRIBUTE_INPUT, rownum rwn
from
(
select distinct ATTRIBUTE_INPUT
from look_up_table
)
) where rwn = ind;
select count( value_for_atr ) into val_count from look_up_table;
for ind in 1..val_count loop
/* putting current value_for_atr for corresponding attribute from look_up_table in temp variable*/
select value_for_atr into temp_val from
(
select value_for_atr, rownum rwn
from look_up_table
) where rwn = ind;
SELECT SUM(CASE WHEN temp_atr_val = temp_val THEN net_sales_home ELSE 0 END) into temp_variable
FROM schemafinal;
/*temp_variable := temp_variable/sales_store;*/
EXECUTE IMMEDIATE 'ALTER TABLE SAR ADD (percent_'||temp_val||' number)';
EXECUTE IMMEDIATE ' update SAR b
set b.percent_'||temp_atr_val||'_'||temp_val||' = 105 ';
END LOOP;
END LOOP;
END;
但是每次代码显示以下两个错误之一时: ORA-01430: column being added already exists in table
- 00000 - “缺少右括号”
当我检查 SAR 表时,其中只有 5 个新列。我不知道为什么会这样,几乎所有方法都试过了。