当前位置:Gxlcms > mysql > 动态执行sql,返回一个值

动态执行sql,返回一个值

时间:2021-07-01 10:21:17 帮助过:48人阅读

动态执行sql,返回一个值 PL/SQL dynamic SQL function dyn_sql(p_sql in varchar2) return varchar2 is c integer; result varchar2(4000); l_temp number; begin c := dbms_sql.open_cursor; dbms_sql.parse(c, p_sql, dbms_sql.native); if upper(p_sql) li

动态执行sql,返回一个值 PL/SQL dynamic SQL
  function dyn_sql(p_sql in varchar2) return varchar2 is
    c      integer;
    result varchar2(4000);
    l_temp number;
  begin
    c := dbms_sql.open_cursor;
    dbms_sql.parse(c, p_sql, dbms_sql.native);
    if upper(p_sql) like 'SELECT%' then
      dbms_sql.define_column(c, 1, result, 4000);
      l_temp := dbms_sql.execute_and_fetch(c);
      if l_temp > 0 then
        dbms_sql.column_value(c, 1, result);
      else
        result := null;
      end if;
    else
      l_temp := dbms_sql.execute(c);
      result := null;
    end if;
    dbms_sql.close_cursor(c);
    return result;
  end dyn_sql;

人气教程排行