呵呵,如果在DELPHI中写的话,我认为不需要这样写的吧,你声明变量可以在DELPHI中声明呀,需要的时候再代入到你的SQL语句中去呀 var a : integer; begin adoquery1.close; adoquery1.sql.add('select * from table1 where fielda = :P_a'); adoquery1.parameters.parambyname('p_a').value := a; adoquery1.open; {...} {如果需要循环取记录或是什么的话,你也可以在DELPHI中定义变量,在数据库中再代入} end;
pl/sql过程不能返回值,若要取值,用函数返回 create function get_value return number as begin return 1; end;with adoconnection1 do begin adoquery.close; adoquery.sql.clear; adoquery.sql.add('create function get_value '); adoquery.sql.add(return number as '); adoquery.sql.add('begin '); adoquery.sql.add(return 1;'); adoquery.sql.add('end;'); adoquery.execsql; adoquery.sql.clear; adoquery.sql.add('select get_value rs from dual'); adoquery.open; .....
我得主要目的是取得sql语句的返回值: 我得语句是 with query do begin Close(); Parameters.AddParameter(); Parameters[0].Name := 'a'; Parameters[0].DataType := ftBoolean; Parameters[0].Direction := pdInputOutput; SQL.Clear(); SQL.AddStrings(memo_sql.Lines); ExecSql(); end;实际的sql语句为 begin :a := false; end;可是执行的时候报错 ORA-01008 不是所有变量都赋了值。
to beckhambobo(beckham): 实际上我在数据库中需要调用一函数: Get_Value(); 该函数不能通过select get_value() from dual 执行, 因为报错: ORA-06571: 函数 GET_VALLUE 不能保证不更新数据库. 因为我不能更改原数据库函数。所以只能通过 declare a boolean; begin a := Get_Value(); end; 执行该函数,我怎样才能取得该返回值那?
var
a : integer;
begin
adoquery1.close;
adoquery1.sql.add('select * from table1 where fielda = :P_a');
adoquery1.parameters.parambyname('p_a').value := a;
adoquery1.open;
{...}
{如果需要循环取记录或是什么的话,你也可以在DELPHI中定义变量,在数据库中再代入}
end;
create function get_value
return number
as
begin
return 1;
end;with adoconnection1 do
begin
adoquery.close;
adoquery.sql.clear;
adoquery.sql.add('create function get_value ');
adoquery.sql.add(return number as ');
adoquery.sql.add('begin ');
adoquery.sql.add(return 1;');
adoquery.sql.add('end;');
adoquery.execsql;
adoquery.sql.clear;
adoquery.sql.add('select get_value rs from dual');
adoquery.open;
.....
我得语句是
with query do
begin
Close();
Parameters.AddParameter();
Parameters[0].Name := 'a';
Parameters[0].DataType := ftBoolean;
Parameters[0].Direction := pdInputOutput;
SQL.Clear();
SQL.AddStrings(memo_sql.Lines);
ExecSql();
end;实际的sql语句为
begin
:a := false;
end;可是执行的时候报错 ORA-01008 不是所有变量都赋了值。
实际上我在数据库中需要调用一函数: Get_Value();
该函数不能通过select get_value() from dual 执行,
因为报错:
ORA-06571: 函数 GET_VALLUE 不能保证不更新数据库.
因为我不能更改原数据库函数。所以只能通过
declare
a boolean;
begin
a := Get_Value();
end;
执行该函数,我怎样才能取得该返回值那?
在上面链接中pipi.好像提到能够返回值,可是不是很详细,有人能解释一下吗?
adoquery.sql.clear;
adoquery.sql.add('select get_value rs from dual');
adoquery.open;
.....
adoquery.fieldvalues('rs'); //获取其值
代码中动态创建函数 跟手工在库中建存储过程有什么区别?不是多此一举吗?
感谢你们的关注!
关于beckham所说的 实际上我在数据库中需要调用一函数: Get_Value();
该函数不能通过select get_value() from dual 执行,
因为报错:
ORA-06571: 函数 GET_VALLUE 不能保证不更新数据库.关于jcc0128所说的:
可能没有办法只能用存储过程了