如何讲字段名作为参数穿给包?

yongnicheng 2010-11-04 10:39:11
比如我一个表 product 有两个字段 A ,B
需求是 不确定要显示哪个字段,
所以打算 将字段在外面 获取到之后传到包里面,
如下的 procudure
我建了一个包TEST,包中包含一个方法get_info(v_column in varchar,p_cursor out TEST.cursortype)

procedure get_info(v_column in varchar,p_cursor out TEST.cursortype)
as
begin
open p_cursor for
select v_column from A;
end;


如果 A和B 都 有的话 v_column 就会传入 A,B
如果 只有 A 的话v_column 就会只传人 A
但是 这样 C# 还是 报错了 ,请问怎么解决?
...全文
100 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
iqlife 2010-11-05
  • 打赏
  • 举报
回复
先定义SQL字符串变量,然后 在OPEN 游标语句即可
kingkingzhu 2010-11-05
  • 打赏
  • 举报
回复
动态拼接sql就可以了
或是using
心中的彩虹 2010-11-05
  • 打赏
  • 举报
回复
[Quote=引用楼主 yangzheng1128 的回复:]
比如我一个表 product 有两个字段 A ,B
需求是 不确定要显示哪个字段,
所以打算 将字段在外面 获取到之后传到包里面,
如下的 procudure
我建了一个包TEST,包中包含一个方法get_info(v_column in varchar,p_cursor out TEST.cursortype)

SQL code

procedure get_info(v_co……
[/Quote]
动态拼接

open p_cursor for 'select '||v_column||' from A';
gelyon 2010-11-05
  • 打赏
  • 举报
回复

--最好用存储过程来做,你需要动态SQL来拼接,用动态游标来返回结果:
create or replace procedure get_info(v_column in varchar,p_cursor out sys_refcursor)
as
begin
open p_cursor for 'select '||v_column||' from A';
end;
minitoy 2010-11-05
  • 打赏
  • 举报
回复
create or replace procedure get_info(v_column in varchar,p_cursor out sys_refcursor)
as
begin
open p_cursor for 'select '||v_column||' from A';
end;
yongnicheng 2010-11-04
  • 打赏
  • 举报
回复
我 是 返回游标类型的 啊,如果 直接在数据库中把 v_COLUMN换成 A 这样 没错的啊
liuyi8903 2010-11-04
  • 打赏
  • 举报
回复
你的语句要动态来执行啦,而不是直接这样呢。
比如:execute immediate 'select ....;

3,494

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧