Home > Database > Mysql Tutorial > body text

动态执行sql,返回一个值

WBOY
Release: 2016-06-07 14:54:59
Original
1251 people have browsed it

动态执行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;
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template