Oracle列别名中的双引号 [英] Double Quotes in Oracle Column Aliases

查看:366
本文介绍了Oracle列别名中的双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是一个晦涩的问题,但是希望有人可以帮助我解决这个问题.

Ok, this is bit of an obscure question, but hopefully someone can help me out with it.

我正在使用的系统构建一个动态SQL字符串,以便在存储过程中执行该动态SQL字符串,并且该动态SQL的一部分定义了列别名,这些别名实际上是从用户生成的数据的另一张表中检索到的值.

The system I'm working on builds a dynamic SQL string for execution inside a stored procedure, and part of that dynamic SQL defining column aliases, which themselves are actually values retrieved from another table of user generated data.

例如,字符串可能看起来像;

So, for example, the string might look something like;

SELECT table1.Col1 AS "This is an alias" FROM table1

这很好.但是,用于别名的值可能会包含双引号字符,这会破坏外部引号.我以为我也许可以以某种方式在别名内转义双引号,但是我没有运气弄清楚如何做到这一点.反斜杠不起作用,并且连续使用两个双引号会导致此错误;

This works fine. However, the value that is used for the alias can potentially contain a double quote character, which breaks the outer quotes. I thought that I could maybe escape double quotes inside the alias somehow, but I've had no luck figuring out how to do so. Backslash doesn't work, and using two double quotes in a row results in this error;

SQL Error: ORA-03001: unimplemented feature
03001. 00000 -  "unimplemented feature"
*Cause:    This feature is not implemented.

以前有人在此问题上有过经验吗? 为任何人的见识而欢呼.

Has anyone had any experience with this issue before? Cheers for any insight anyone has.

p.s.别名周围需要使用引号,因为它们可以包含空格.

p.s. the quotes are needed around the aliases because they can contain spaces.

推荐答案

是否可以在代码中放置另一个字符而不是双引号并将其替换为双引号?

Can you just put another character instead of double quotes and replace that with double quotes in the code?

类似这样的东西:

SELECT table1.Col1 AS "This is |not| an alias" FROM table1

然后只需替换|与.

我知道这是一个hack,但是我想不出更好的解决方案了……无论如何,您在做什么. 不错"的方法是分别选择值和列名,并将它们与代码关联.那样会使事情变得更加干净.

I know it's a hack, but I can't think of any better solution... And what you are doing there is a hack anyway. The "nice" way would be to select the values and the column names separately and associate them in your code. That would make things much cleaner.

这篇关于Oracle列别名中的双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆