Oracle中创建存储过程、运行动态SQL并得到动态SQL语句所查询的值

本文介绍了如何在Oracle中创建存储过程,使用动态SQL来查询数据,并将查询结果赋值给传出参数。通过示例展示了如何根据设备ID获取历史表中的最新数据,着重关注动态构建SQL语句及执行过程。
摘要由CSDN通过智能技术生成
create or replace procedure proc_getnewfuhebyfacid(fac_id_s in varchar2,fac_id_e in varchar2,newfuhe_s out varchar2,newfuhe_e out varchar2)
is
tempaclnid varchar2(20);
temp_s_aclndotid varchar2(20);
temp_e_aclndotid varchar2(20);

table_names varchar2(20);
table_columns varchar2(20);
sqls varchar2(1000);--存放动态SQL的语句

begin
  select acln_id into tempaclnid from acln_device where fac_id_s = fac_id_s and fac_id_e =fac_id_e and rownum <2;
  select acln_dot_id into temp_s_aclndotid from acln_dot where acln_id = tempaclnid and fac_id=fac_id_s;
  select acln_dot_id into temp_e_aclndotid from acln_dot where acln_id = tempaclnid and fac_id=fac_id_e;

  select history_table_name,history_column_name into table_names,table_columns from svr_yc_sample_define where yc_id like '%'||temp_s_aclndotid||'%' and rownum<2;
  sqls:='select '||table_columns||' from (select  * from '||table_names||' where to_c
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值