type curs is ref cursor;动态游标
cu3 curs;
open cu3 for 'select code_segment_start,code_segment_length,code_zone_id from zc.t_gx_rule_detail  where field_id='||v_field_id;
loop
fetch cu3 into v_code_segment_start,v_code_segment_length,v_code_zone_id;
exit when cu3%notfound;我想问下,我用动态游标,想从数据表中取出 field_id=v_field_id.的记录,这样写有问题吗?
我这样写运行的时候抱"无效列名"的错误
请哪位大哥帮帮我

解决方案 »

  1.   

    open cu3 for 'select code_segment_start,code_segment_length,code_zone_id from zc.t_gx_rule_detail  where field_id='''||v_field_id||'''';
      

  2.   

    sql*plus里面执行
    select code_segment_start,code_segment_length,code_zone_id from zc.t_gx_rule_detail  where field_id=1;
    有没有错误?
      

  3.   

    没有错误
    就这样说好来:就是我要查询一个表t_X.通过条件id=condition1
    返回一个cursor
    我该怎么写啊?我是这样写的
    type curs is ref cursor;
    cu3 curs;
    tmp tX%rowtype;
    begin
    open cu3 for 'select * from t_X where id='||condition1||'';
    loop
    fetch cu3 into tmp;
    exit when cu3%notfound;
    ....end loop;
      

  4.   

    open cu3 for 'select code_segment_start,code_segment_length,code_zone_id from zc.t_gx_rule_detail  where field_id='||v_field_id;错误,运行的时候错误
    open cu3 for 'select code_segment_start,code_segment_length,code_zone_id from zc.t_gx_rule_detail  where field_id=001';正确,有多条记录返回
      

  5.   

    是不是v_field_id存放的数据有问题?
      

  6.   

    哎哟,我把数据搞出来看了,晕倒,原来是有一条数据那个字节为NULL.哎搞了我半天,郁闷啊.谢谢你了,给你加分了