我有使用此变量的脚本
with
TIME_DATA as ( select $$D:=:DA$$ td from dual),
GROUP_INFO as (select $$N:=:GR_ID$$ gr_id_number from dual),
并像这样使用它们
A_PLUS_TEK as(select point_id, ml_id, ml_name, val a_plus_month, DA
from VALUE_DATA, TIME_DATA
where ml_id = 381 and DA = trunc(td, 'MM'))
我想知道如何初始化这些变量,现在当我运行脚本时,我有这个输出:
Bind Variable "DA$$" is NOT DECLARED
编辑:通常用户在网站上输入此值,我只能访问数据库,我从报告表中获取脚本。另外,我想知道如何从c#初始化这些变量。
EIDT2:我以此为例(How do I use variables in Oracle SQL Developer?)。它有效。
variable v_count number;
variable v_emp_id number;
exec :v_emp_id := 1234;
exec select count(1) into :v_count from emp;
select *
from emp
where empno = :v_emp_id
exec print :v_count;
我的代码:
declare
variable DA$$ VARCHAR2(80);
variable gr_id$$ number;
begin
exec :DA$$ := to_date('2011-09-13 09:00:00', 'YYYY-MM-DD HH24:MI:SS');
exec :gr_id$$ := '1341';
BEGIN
然后声明:
WITH
TIME_DATA as ( select $$D:=:DA$$ td from dual),
GROUP_INFO as (select $$N:=:GR_ID$$ gr_id_number from dual),
....
END;
但仍然有这个
Bind Variable "DA$$" is NOT DECLARED
anonymous block completed
这也没有改变
exec :DA$$ := '2011-09-13 09:00:00';
我认为DA $$是日期,因为它在trunc()DA = trunc(td, 'MM'))
中使用
当我选择Run Statement(trl + Enter)时,Sql Developer提供输入绑定变量,但我不知道如何输入日期。
EDIT3:最后,我在没有声明,开始,结束的情况下这样做,并且它有效:
variable DA$$ VARCHAR2(80);
variable gr_id$$ number;
exec :DA$$ := to_date('2011-09-13 09:00:00', 'YYYY-MM-DD HH24:MI:SS');
exec DBMS_OUTPUT.PUT_LINE(:DA$$);
exec :gr_id$$ := '1341';
with
TIME_DATA as ( select $$D:=DA$$; td from dual),
GROUP_INFO as (select $$N:=:GR_ID$$ gr_id_number from dual),
...
答案 0 :(得分:1)
从C#开始你可以这样做:
// using Oracle.DataAccess.Client
using(OracleCommand command = new OracleCommand(commandText, dbConnection))
{
command.CommandType = CommandType.Text;
command.Parameters.Add("DA$$", OracleDbType.Int32, valueDA, ParameterDirection.Input);
command.Parameters.Add("GR_ID$$", OracleDbType.Int32, valueGR_ID, ParameterDirection.Input);
}
但请查看您的命令文本。因为“$$ D:”和“$$ N:”
,您可能会遇到语法错误