---
title: "execute immediate cursor"
author: "jackrenming"
date: "2010-05-13T17:45:33Z"
tags: []
categories: ["数据库"]
slug: "execute-immediate-cursor"
draft: false
lastmod: "2010-05-13T17:45:33Z"
id: 665843
url: "https://jackrenming.iteye.com/blog/665843"
---

ORACLE存储过程中动态SQL语句传值给游标解决方案：
create or replace procedure pro_test
  as
TYPE ref_cursor_type IS REF CURSOR;
ctxx ref_cursor_type;
xhcs varchar2(10);
v_sql varchar2(100);
sqlStr varchar2(100);
  begin
  v_sql := 'select xh from a_test';
  open   ctxx   for   v_sql;
   loop
                       fetch ctxx into xhcs;
                       exit when ctxx%notfound;
                            sqlStr := 'insert into a_test2 values('||xhcs||')';
                            execute immediate sqlStr;
                    end loop;
                   close ctxx;
   commit;
  end;