StoredProc1.close;
StoredProc1.params[0]:='1234321';
StoredProc1.params[1]:='HelloWorld';
try
StoredProc1.open;
except
raise exception.create('error');
end;
如果是在存储过程中直接调用记录中的变量作参数, 可以使用游标:
下面是SQL Server的游标(Cursor)的调用方法:
Declare @vTableName sysname
Declare @i int
set @i = 0
Declare cr_table CURSOR --定义游标
FOR
select name from sysobjects where xtype = 'U' and uid =
(select uid from sysusers where name = 'Createnew') --
open cr_table
FETCH NEXT FROM cr_table INTO @vtablename //取游标数据到变量@vtablename
WHILE (@@FETCH_status = 0)
begin
set @i = @i + 1
set @vTableName = 'Createnew.'+@vTableName
print @vTableName
FETCH Next FROM cr_table INTO @VtableName //取游标数据到变量@vtablename
end
CLOSE Cr_table //关闭游标
select @i
DEALLOCATE Cr_Table --Removes
下面是Oracle的游标的调用方法:
来自:arm 时间:2001-07-10 16:40:00 ID:585335
CREATE OR REPLACE PROCEDURE do_two_unrelated_actions
(tab_in IN VARCHAR2)
IS
cur INTEGER := DBMS_SQL.OPEN_CURSOR;
BEGIN
/* Piece together a CREATE INDEX statement. */
DBMS_SQL.PARSE (cur, 'Select * From' || tab_in , DBMS_SQL.NATIVE);
DBMS_SQL.EXECUTE (cur);
DBMS_SQL.CLOSE_CURSOR (cur);
END;
在DBMS_SQL.EXECUTE (cur)后怎么访问结果集?
ROCEDURE fill_block (where_clause_in IN VARCHAR2)
IS
c INTEGER := DBMS_SQL.OPEN_CURSOR;
emprec employee%ROWTYPE;
employee_id integer;
employee_nm varchar2(30);
fdbk INTEGER;
BEGIN
DBMS_SQL.PARSE (c, 'SELECT employee_id, last_name ' ||
' FROM employee' , DBMS_SQL.NATIVE);
DBMS_SQL.DEFINE_COLUMN (c, 1, emprec.empno);
DBMS_SQL.DEFINE_COLUMN (c, 2, emprec.ename, 30);
fdbk:= DBMS_SQL.EXECUTE (c);
LOOP
EXIT WHEN DBMS_SQL.FETCH_ROWS (c) = 0;
DBMS_SQL.COLUMN_VALUE (c, 1, emprec.empno);
DBMS_SQL.COLUMN_VALUE (c, 2, emprec.ename);
employee_id := emprec.empno;
employee_nm := emprec.ename;
END LOOP;
/* Clean up the cursor */
DBMS_SQL.CLOSE_CURSOR (c);
END;