oracle 一次执行多sql语句的问题!
两条sql语句均能正常运行,但我想合并一起查询string sql = @"begin
select arr_name,arrival,stn_line_name from b_trainline_ttime where stn_name='pp' and mod(to_number(substr(ccsxx(arr_name),length(ccsxx(arr_name)),1)),2)=0 and arrival >=to_date(:startdate1,'yyyy-mm-dd hh24:mi:ss') and arrival <= to_date(:enddate1,'yyyy-mm-dd hh24:mi:ss') order by arrival;
select arr_name,arrival,stn_line_name from b_trainline_ttime where stn_name='pp' and mod(to_number(substr(ccsxx(arr_name),length(ccsxx(arr_name)),1)),2)=1 and arrival >=to_date(:startdate2,'yyyy-mm-dd hh24:mi:ss') and arrival <= to_date(:enddate2,'yyyy-mm-dd hh24:mi:ss') order by arrival;
end;";
OracleConnection oracon = new OracleConnection(conString);
OracleCommand cmd = new OracleCommand(sql.Replace("r\n", " ").Replace('\n', ' '), oracon);
出错提示:ora-06550:line 1,column 7:
pls-00103:encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma raise return select
update while with <an identifier> ...... --------------------编程问答-------------------- 两条语句中添加个试试union --------------------编程问答--------------------
string sql = "select arr_name,arrival,stn_line_name from b_trainline_ttime where stn_name='pp' and mod(to_number(substr(ccsxx(arr_name),length(ccsxx(arr_name)),1)),2)=0 and arrival >=to_date(:startdate1,'yyyy-mm-dd hh24:mi:ss') and arrival <= to_date(:enddate1,'yyyy-mm-dd hh24:mi:ss') order by arrival--------------------编程问答-------------------- 和原先提示一样!!! --------------------编程问答-------------------- 先把SQL语句放到数据库中执行,确保SQL语句是否正常,不正常的原因是什么 --------------------编程问答-------------------- 1、先不要order by
union
select arr_name,arrival,stn_line_name from b_trainline_ttime where stn_name='pp' and mod(to_number(substr(ccsxx(arr_name),length(ccsxx(arr_name)),1)),2)=1 and arrival >=to_date(:startdate2,'yyyy-mm-dd hh24:mi:ss') and arrival <= to_date(:enddate2,'yyyy-mm-dd hh24:mi:ss') order by arrival"
select a b c
(select a,b,c from
A
union all
select a,b,c from
B
) from C
order by order by arrival
--------------------编程问答-------------------- 语句确认都没有问题,都亲自试过了 --------------------编程问答-------------------- 是说合并的SQL语句一起运行,而不是分开运行;如果都成功了那还能关SQL语句什么问题,说明是其他地方问题 --------------------编程问答-------------------- 查询不行的,更新删除可以。 --------------------编程问答-------------------- 查询要两个合并就用union all,或union(看业务情况),将多条语句合成一句。这样的话就不要再加begin end了。直接正常语法就行了。 --------------------编程问答-------------------- 你的代码直接写成这样就行了。一句就行,没必要那么烦。
select arr_name,arrival,stn_line_name from b_trainline_ttime where stn_name='pp'--------------------编程问答-------------------- 多条语句.用事务. --------------------编程问答-------------------- 我想要分别绑定到两个datagridview中,所以分开写 --------------------编程问答-------------------- 5楼正解+1 --------------------编程问答-------------------- 我想要分别绑定到两个datagridview中,所以分开写,在sqlserver中就一个“;”号搞定了,难道oracle就无法实现? --------------------编程问答-------------------- 这样试试:
and((mod(to_number(substr(ccsxx(arr_name),length(ccsxx(arr_name)),1)),2)=0 and arrival >=to_date(:startdate1,'yyyy-mm-dd hh24:mi:ss') and arrival <= to_date(:enddate1,'yyyy-mm-dd hh24:mi:ss'))or(mod(to_number(substr(ccsxx(arr_name),length(ccsxx(arr_name)),1)),2)=1 and arrival >=to_date(:startdate2,'yyyy-mm-dd hh24:mi:ss') and arrival <= to_date(:enddate2,'yyyy-mm-dd hh24:mi:ss')))
order by arrival;
DataSet DSData=new DataSet();
string sql=“select1”;
OracleConnection oracon = new OracleConnection(conString);
OracleDataAdapter oraadapter=new OracleDataAdapter(sql,oracon);
oraadapter.Fill(DSData,"Table1");
sql="select2";
oraadapter=new OracleDataAdapter(sql,oracon);
oraadapter.Fill(DSData,"Table2");
两个datagridview 分别绑定到DataSet的两个表 --------------------编程问答-------------------- jian200801这样可以,目前我也是这样实现的,如果要把两条语句写到一起,提高效率,到底该如何写?在sqlserver中用;号就能搞定,在oracle中该如何书写呢?
补充:.NET技术 , C#