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

来源:百度文库 编辑:神马文学网 时间:2024/10/06 00:17:59
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;          --动态执行SQLEND 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_nameCREATE 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