Oracle 向过程添加调试信息时出现问题
Oracle problem adding debug information to procedure
我正在尝试将一些 DEBUGGING 信息添加到我的程序中,但我似乎无法编译它,尽管其中大部分已被注释掉。问题似乎出在第 29 行。如有任何帮助,我们将不胜感激。
create or replace
procedure drop_partition(
p_tab varchar2,
p_date date
)
authid current_user
is
v_high_value date;
v_sql_stmt varchar2(200);
cursor v_cur
is
select table_name,
partition_name,
high_value,
partition_position
from user_tab_partitions
where table_name = upper(p_tab);
begin
for v_rec in v_cur loop
execute immediate 'select ' || v_rec.high_value || ' from dual'
into v_high_value;
if ( v_high_value <=
trunc(p_date)) and
v_rec.partition_position != 1
then
dbms_output.put_line ('partition ' || v_rec.partition_name || ' high value is ' || to_char(v_high_value,'mm/dd/yyyy'));
-- v_sql_stmt :=
'EXECUTE IMMEDIATE ALTER TABLE ' || p_tab || ' DROP PARTITION FOR(DATE ' || TO_CHAR(v_high_value,'YYYY-MM-DD') || ')';
v_sql_stmt := 'execute immediate alter table '||p_tab||' drop partition '||v_rec.partition_name';';
--dbms_output.put_line(v_sql_stmt);
--EXECUTE IMMEDIATE v_sql_stmt;
end if;
end loop;
end;
/
v_sql_stmt := 'execute immediate alter table '||p_tab||' drop partition '||v_rec.partition_name';';
在末尾附近缺少一个 ||
运算符。
您也不希望在要使用 EXECUTE IMMEDIATE
执行的字符串中使用 EXECUTE IMMEDIATE
。
像这样:
create procedure drop_partition(
p_tab varchar2,
p_date date
) authid current_user
is
v_high_value date;
v_sql_stmt varchar2(200);
cursor v_cur is
select table_name,
partition_name,
high_value,
partition_position
from user_tab_partitions
where table_name = upper(p_tab);
begin
for v_rec in v_cur loop
execute immediate 'select ' || v_rec.high_value || ' from dual' into v_high_value;
if v_high_value <= trunc(p_date)
and v_rec.partition_position != 1
then
dbms_output.put_line (
'partition ' || v_rec.partition_name || ' high value is '
|| to_char(v_high_value, 'mm/dd/yyyy')
);
v_sql_stmt := 'alter table '||p_tab||' drop partition '||v_rec.partition_name;
dbms_output.put_line(v_sql_stmt);
EXECUTE IMMEDIATE v_sql_stmt;
end if;
end loop;
end;
/
我正在尝试将一些 DEBUGGING 信息添加到我的程序中,但我似乎无法编译它,尽管其中大部分已被注释掉。问题似乎出在第 29 行。如有任何帮助,我们将不胜感激。
create or replace
procedure drop_partition(
p_tab varchar2,
p_date date
)
authid current_user
is
v_high_value date;
v_sql_stmt varchar2(200);
cursor v_cur
is
select table_name,
partition_name,
high_value,
partition_position
from user_tab_partitions
where table_name = upper(p_tab);
begin
for v_rec in v_cur loop
execute immediate 'select ' || v_rec.high_value || ' from dual'
into v_high_value;
if ( v_high_value <=
trunc(p_date)) and
v_rec.partition_position != 1
then
dbms_output.put_line ('partition ' || v_rec.partition_name || ' high value is ' || to_char(v_high_value,'mm/dd/yyyy'));
-- v_sql_stmt :=
'EXECUTE IMMEDIATE ALTER TABLE ' || p_tab || ' DROP PARTITION FOR(DATE ' || TO_CHAR(v_high_value,'YYYY-MM-DD') || ')';
v_sql_stmt := 'execute immediate alter table '||p_tab||' drop partition '||v_rec.partition_name';';
--dbms_output.put_line(v_sql_stmt);
--EXECUTE IMMEDIATE v_sql_stmt;
end if;
end loop;
end;
/
v_sql_stmt := 'execute immediate alter table '||p_tab||' drop partition '||v_rec.partition_name';';
在末尾附近缺少一个 ||
运算符。
您也不希望在要使用 EXECUTE IMMEDIATE
执行的字符串中使用 EXECUTE IMMEDIATE
。
像这样:
create procedure drop_partition(
p_tab varchar2,
p_date date
) authid current_user
is
v_high_value date;
v_sql_stmt varchar2(200);
cursor v_cur is
select table_name,
partition_name,
high_value,
partition_position
from user_tab_partitions
where table_name = upper(p_tab);
begin
for v_rec in v_cur loop
execute immediate 'select ' || v_rec.high_value || ' from dual' into v_high_value;
if v_high_value <= trunc(p_date)
and v_rec.partition_position != 1
then
dbms_output.put_line (
'partition ' || v_rec.partition_name || ' high value is '
|| to_char(v_high_value, 'mm/dd/yyyy')
);
v_sql_stmt := 'alter table '||p_tab||' drop partition '||v_rec.partition_name;
dbms_output.put_line(v_sql_stmt);
EXECUTE IMMEDIATE v_sql_stmt;
end if;
end loop;
end;
/