日期:2014-05-17  浏览次数:20899 次

求助oracle大师,帮忙看下这个函数哪错了
IF p_grid_type_id != v_type_id THEN
  v_tabel_name := get_table_name(p_grid_type_id);
  v_tabel_name_1 := get_table_name(p_grid_type_id_1); 
  UPDATE gs_grid_info t
  SET t.grid_type_id = p_grid_type_id
  WHERE t.gwm_fid = p_gwm_fid;
  v_sql := 'INSERT INTO '|| v_tabel_name_1 ||
  'SELECT * 
  FROM '|| v_tabel_name ||' c
  WHERE c.gwm_fid = '|| p_gwm_fid;
  EXECUTE IMMEDIATE v_sql;  
  v_sql := 'DELETE FROM ' || v_tabel_name ||' c 
  WHERE c.gwm_fid = '|| p_gwm_fid;
  EXECUTE IMMEDIATE v_sql;
  IF p_grid_type_id = v_type_id THEN
  DELETE FROM r_grid_address t
  WHERE t.grid_id = p_gwm_fid;
  COMMIT;
  RETURN 1;  
  ELSE
  COMMIT;
  RETURN 1;
  END IF;  
ELSE
  RETURN 0;
END IF;

------解决方案--------------------
UPDATE gs_grid_info t
SET t.grid_type_id = p_grid_type_id
WHERE t.gwm_fid = p_gwm_fid;


ORACLE的函数里不能使用DML语句。
------解决方案--------------------
函数不是用来计算并返回值的吗 你为什么要执行update语句啊
这有违函数的初衷吧
如果想用update,最好是使用存储过程 而不是函数