简体   繁体   English

如何在查询字符串KSH Linux中转义管道“ |”字符?

[英]How do I escape pipe “|” character in query string KSH Linux?

I need to execute this query in sqlplus: 我需要在sqlplus中执行以下查询:

q="
SELECT  count(*) cnt FROM all_tables WHERE UPPER(OWNER||'.'||TABLE_NAME)=UPPER('$tab_')"

but pipe "|" 但是管道“ |” get interpreted in KSH: 在KSH中得到解释:

echo $q

SELECT  count(*) cnt FROM all_tables WHERE UPPER(OWNER  '.'  TABLE_NAME)=UPPER('STGDATA.T_DEL_RW_FIFO_PL_HIS_SC')

How do I escape them so query can be executed in sqlplus? 我如何转义它们,以便可以在sqlplus中执行查询?

i don't have linux to test but on openbsd ksh it doesn't make it disappear 我没有要测试的linux,但在openbsd ksh上却没有使其消失

$ ./escape.sh
/bin/ksh -> SELECT count(*) cnt FROM all_tables WHERE UPPER(OWNER||'.'||TABLE_NAME)=UPPER('')
$ cat escape.sh
#!/bin/sh
q="SELECT  count(*) cnt FROM all_tables WHERE UPPER(OWNER||'.'||TABLE_NAME)=UPPER('$tab_')"
echo $SHELL "->" $q

but try the normal backslash escape like 但是尝试正常的反斜杠转义

$ echo \|\|
||

if what you have there is a multiline string (cause i see that line break between " and the SELECT i would suggest using a cat << EOF construct. 如果您有一个多行字符串(因为我看到“和SELECT之间的换行符,我建议使用cat << EOF构造。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM