sqlplus 中带有替换变量的请求之间的联合
我有 14 个相似的字段,我在每个字段上搜索字符串“A”。我想在按“位置”字段排序后
-- some set in order to remove a lot of useless text
def col='col01'
select '&col' "Fieldname",
&col "value",
position
from oneTable
where &col like '%A%'
/
-- then for the second field, I only have to type two lines
def col='col02'
/
...
def col='col14'
/
写入包含“A”的所有字段。问题是这些字段不是按位置排序的。
如果我在表之间使用 UNION,则无法利用替换变量 (&col),并且我必须在 unix 中编写 bash 以便将替换返回到 ksh 中。问题当然是数据库代码必须在这个脚本中硬编码(连接不是一件容易的事情)。
如果我将 REFCURSOR 与 OPEN 一起使用,则无法将结果集分组在一起。我只有一个请求,无法将其联合起来。 (print refcursor1 union refcursor2;print refcursor1+refcursor2 引发异常,select * from refcursor1 union select * from refcursor2,也不起作用)。
如何将结果连接成一个大的“REFCURSOR”?或者在我的请求的两个不同的运行(“/”)之间使用联合,例如在键入新的变量定义时保留请求?
感谢您的任何建议。
I have 14 fields which are similar and I search the string 'A' on each of them. I would like after that order by "position" field
-- some set in order to remove a lot of useless text
def col='col01'
select '&col' "Fieldname",
&col "value",
position
from oneTable
where &col like '%A%'
/
-- then for the second field, I only have to type two lines
def col='col02'
/
...
def col='col14'
/
Write all the fields which contains 'A'. The problem is that those field are not ordered by position.
If I use UNION between table, I cannot take advantage of the substitution variables (&col), and I have to write a bash in unix in order to make the replacement back into ksh. The problem is of course that database code have to be hard-coded in this script (connection is not easy stuff).
If I use a REFCURSOR with OPEN, I cannot group the results sets together. I have only one request and cannot make an UNION of then. (print refcursor1 union refcursor2; print refcursor1+refcursor2 raise an exception, select * from refcursor1 union select * from refcursor2, does not work also).
How can concatenate results into one big "REFCURSOR"? Or use a union between two distinct run ('/') of my request, something like holding the request while typing new definition of variables?
Thank you for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这能回答你的问题吗?
但我不完全确定您使用名为“col”的“替换变量”(并且我只有 SQL Server 来测试我的请求,所以我使用了显式字段名称)
编辑:抱歉“#”字符,我们使用它在 SQL Server 中经常用于临时表,我什至不知道它是 SQL Server 特定的(而且我认为它在 sql server 中创建临时表是强制性的)。不管怎样,我很高兴我能对你有用。
Does this answer your question ?
But I'm not totally sure about your use of the 'substitution variable' called "col" (and i only have SQL Server to test my request so I used explicit field names)
edit : Sorry for the '#' charcater, we use it so often in SQL Server for temporaries, I didn't even know it was SQL Server specific (moreover I think it's mandatory in sql server for creating temporary table). Whatever, I'm happy I could be useful to you.