BASH - SQL Where 子句的双引号内的单引号
我需要将格式正确的日期比较 WHERE 子句发送到 bash 命令行上的程序。
一旦进入被调用的程序,WHERE 子句就应该对 Oracle 有效,并且应该看起来完全像这样:
highwater>TO_DATE('11-Sep-2009', 'DD-MON-YYYY')
日期值在变量中。我尝试了引号和反斜杠的各种组合。我不想混淆问题并给出我的错误的例子,而是希望得到一个原始准确的答案,没有被垃圾玷污。
如果我用 Perl 编写它,我认为作业看起来像这样:
$hiwaterval = '11-Sep-2009';
$where = "highwater>TO_DATE(\'$hiwaterval\', \'DD-MON-YYYY\')";
How do I meet the sameeffect in bash?
I need to send a properly formatted date comparison WHERE clause to a program on the command line in bash.
Once it gets inside the called program, the WHERE clause should be valid for Oracle, and should look exactly like this:
highwater>TO_DATE('11-Sep-2009', 'DD-MON-YYYY')
The date value is in a variable. I've tried a variety of combinations of quotes and backslashes. Rather than confuse the issue and give examples of my mistakes, I'm hoping for a pristine accurate answer unsullied by dreck.
If I were to write it in Perl, the assignment would I think look like this:
$hiwaterval = '11-Sep-2009';
$where = "highwater>TO_DATE(\'$hiwaterval\', \'DD-MON-YYYY\')";
How do I achieve the same effect in bash?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果要在当前 shell 中可见,则可以选择在最终变量设置之前添加“export”。
optionally add "export " before final variable setting if it is to be visible ourside the current shell.
您是否尝试过使用双勾?就像高潮>TO_DATE(''11-Sep-2009'', ''DD-MON-YYYY'')。只是一个建议。我还没试过。
Have you tried using using double ticks? Like highwater>TO_DATE(''11-Sep-2009'', ''DD-MON-YYYY''). Just a suggestion. I haven't tried it out.
您可以像这样分配 where 子句:(
在 echo 语句周围使用反引号 - 它们不会出现在我的编辑器中...)
它与以下形式的 shell 脚本一起使用:
You can assign the where clause like this:
(with backticks around the echo statement - they're not showing up in my editor here...)
which works with a shell script of the form: