多个oracle查询问题
我正在尝试从 .NET 页面运行查询,但似乎在进行多个查询时遇到一些问题。
我的查询类似于此
SELECT * FROM table1; SELECT * from table2
但从 .Net 页面执行此操作时,我似乎收到无效字符错误。它在 SQL Developer 中运行良好,但仅当我将其放入 .NET 页面时才会失败。
我已将 BEGIN
和 END
添加到查询中,因为某些网站建议您需要它来运行多个查询,但随后出现以下错误
ORA-06550: 第 1 行,第 7 列: PLS-00428:此 SELECT 语句中需要 INTO 子句
有谁能解释一下这一点吗?
提前致谢!
编辑
这是一些代码
query = conn.CreateCommand()
query.CommandText = "SELECT * from table1; SELECT * FROM table2;"
DataSet = New DataSet()
DataAdapter = New DataAdapter(query)
DataAdapter.Fill(DataSet)
datagrid1.DataSource = DataSet.Tables(0)
datagrid1.DataBind()
lbl1.Text = DataSet.Tables(1).Rows(0).Item("column1").ToString()
I'm trying to run a query from a .NET page but I seem to having some problems with having multiple queries.
My query is similar to this
SELECT * FROM table1; SELECT * from table2
But i seem to get an invalid character error when executing this from a .Net page. It runs fine in SQL developer but only fails when i put it in my .NET page.
I've added the BEGIN
and END
to the query as some websites suggest you need this to run multiple queries but then I get the following error
ORA-06550: line 1, column 7:
PLS-00428: an INTO clause is expected in this SELECT statement
Can anyone shed any light on this one?
Thanks in advance!
EDIT
Here's some code
query = conn.CreateCommand()
query.CommandText = "SELECT * from table1; SELECT * FROM table2;"
DataSet = New DataSet()
DataAdapter = New DataAdapter(query)
DataAdapter.Fill(DataSet)
datagrid1.DataSource = DataSet.Tables(0)
datagrid1.DataBind()
lbl1.Text = DataSet.Tables(1).Rows(0).Item("column1").ToString()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想从 2 个表中提取数据并获取可填充到 DataAdapter 中的 DataSet,则需要使用以下方法之一:
您无法仅运行 2 个这样的 SQL 语句并在数据集中获取任何有意义的结果。
If you want to pull from 2 tables and get a DataSet that you can fill into a DataAdapter, then you need to use one of the following approaches:
You're not going to be able to just run 2 SQL statements like that and get any meaningful result into a DataSet.
为陈述显而易见的事实而道歉,但是:
1.. 进行 2 次调用
或
2.. 将选择放入存储过程并返回 2 个引用游标,
这是有关使用多个结果集的一个很好的链接:
http://msdn.microsoft.com/en-us/library/ms971506 .aspx#msdnorsps_topic13
Apologies for stating the obvious but:
1.. Make 2 calls
or
2.. Put the selects in a stored procedure and return 2 refcursors
here's a good link on Working with Multiple Result Sets:
http://msdn.microsoft.com/en-us/library/ms971506.aspx#msdnorsps_topic13
如果您只需要 table1 和 table2 中都存在的字段,您可以这样做
如果字段具有不同的名称,但您可以执行相同类型的内容
这将为您提供包含 Primary_key、name、amount 列的结果(这只是一个随机示例)
如果两个表包含完全不同的内容,那么您确实应该使用两个单独的查询。
If you only need fields that are present in both table1 and table2 you can do
If the fields have different names but the same type of content you can do
This will give you a result with the columns primary_key, name, amount (this is just a random example)
If the two tables contain completely different content, you should really use two separate queries.
可能的解决方案可能是
...如 DataSet.Load:使用 System.Data.OracleClient.OracleDataReader 加载多个表 ...但我自己没有测试过。
另请查看 http://forums.asp.net/t/629511.aspx/1< /a>.它展示了如何,某种程度上。我添加了对 Oracle.DataAccess.Types; 的引用,但仍然有问题。不过也很接近了。
A possible solution could be
... as found in DataSet.Load: Loading multiple tables with System.Data.OracleClient.OracleDataReader ... but not tested myself.
Also check out http://forums.asp.net/t/629511.aspx/1. It shows how, sort of. I added a reference to Oracle.DataAccess.Types;, but still had a problem. It's close though.