在存储过程中select to_char(sysdate - n, 'yyyymmdd') into part_name from dual;part_name:='PART_'||part_name; --分区名select id into v_id
from sd.user partition(part_name)
where xxxxxxxxxxxxxxxxxx但是运行到标红的那条就报错,说是找不到该分区,但是把拼接后的值直接放到partition的括号里是没有问题的。我觉得oracle 没有把 part_name 的值取出来,直接把part_name当做分区名字了,这个怎么办啊?

解决方案 »

  1.   

    execute immediate 'select id  from sd.user partition('||part_name||')' into v_id;
      

  2.   

    恩, 谢谢楼上的, 我试试, 看楼下有木有其他好的方式 ? 例如绑定变量能搞定不?
    execute immediate 'select id from sd.user partition(:x)' into v_id using part_name;类似这样的
      

  3.   


    execute immediate 'select id from sd.user partition(:x)' into v_id using part_name;
    --绑定变量不就是给他传递一个参数嘛!道理是一样的
      

  4.   


    虽然原理一样,但是编译过程中不允许动态指定partition,, 直到现在没找到好的方式。