分享

INFORMIX IDS11.5 动态存储过程(DYNAMIC SPL) - INFORM...

 snowlewolf 2009-11-19
INFORMIX IDS11支持 动态存储过程。本文通过举例的方法演示如何在INFORMIX中创建动态存储过程。
EXAMPLE 1 
说明 EXECUTE IMMEDIATE 语句
可以通过参数名来动态执行不同的表
DATABASE stores_demo;
   
CREATE PROCEDURE create_tab (table_name CHAR(128), column_list CHAR(512))
   DEFINE l_crtstmt   CHAR(1024);
   LET l_crtstmt = "CREATE TABLE " || table_name ||"("|| column_list || " )";  --动态语句,存放到一个变量中
   EXECUTE IMMEDIATE l_crtstmt;          --动态执行SQL
END PROCEDURE;
执行存储过程
EXECUTE PROCEDURE create_tab ("tmp_cust","cust_num INTEGER,cust_fname CHAR(30)");

--------------------------------------------------------------------------------
EXAMPLE 2
说明在SPL中如何利用游标和动态语句
DATABASE stores_demo;
-- Procedure to dynamically constructs query `cust_qry' using supplied
-- table_name and returns all rows whose first name is the supplied
-- first_name
CREATE PROCEDURE customer_details(table_name CHAR(30),first_name CHAR(30))
RETURNING INTEGER, CHAR(30), CHAR(30), CHAR(30);
   DEFINE cust_qry VARCHAR(250);
   DEFINE l_cust_num INTEGER;
   DEFINE l_fname CHAR(30);
   DEFINE l_lname CHAR(30);
   DEFINE l_state CHAR(30);
   -- Construct a Dynamic query using SPL argument table_name
   LET cust_qry = "select customer_num, fname, lname, state from "
||table_name || " where fname = ?";
   -- Prepare the above constructed query
   -- Get the statement handle "statement_id"
   PREPARE stmt_id FROM cust_qry;
-- Declare the cursor for the prepared "statement_id"
-- get the cursor handle "cust_cur"
DECLARE cust_cur cursor FOR stmt_id;
           -- Open the declared cursor using handle "cust_cur"
           -- Supply the first_name as an input. This will be
           -- substituted in the place of "?" in the query
 
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ibminformix/archive/2009/11/19/4833481.aspx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多