欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

在Oracle PL/SQL中游标声明中表名动态变化的方法

程序员文章站 2023-11-04 22:36:04
/*     小弟刚刚接触oracle存储过程,有一个问题向各位同行求教,小弟写了一个存储过程,其目的是接收一个参数作为表名,然后查...
/*
    小弟刚刚接触oracle存储过程,有一个问题向各位同行求教,小弟写了一个存储过程,其目的是接收一个参数作为表名,然后查询该表中的全部记录的某一个字段的内容导入到另一个表中。
    (
    tabname in varchar
    )
    is
    v_servicesname tabname.服务类型%type; --这个变量就是用来存放所要取得的字段内容,但不知该如何定义
    cursor cursort1 is select 服务类型 from tabname order by 编码; --此语句也不对提示找不到表名

    begin
    .....
    end getservicesname1;
        an example:

        create or replace procedure cal(tb varchar2) is
        id pls_integer;
        total pls_integer := 0;
        type emp_cur is ref cursor;
        cur emp_cur;
        begin
        open cur for 'select employee_id from ' || tb;
        loop
        fetch cur into id;
        exit when cur%notfound;

        total := total + id;
        end loop;
        close cur;

        dbms_output.put_line(total)
        end;*/