如何转义 Oracle Forms 10g varchar2 变量中的 Linux 字符串

How can I escape a Linux string in Oracle Forms 10g varchar2 variable

如果我无法清楚地提出问题,请原谅我。

我正在尝试从 Oracle Forms 10g 过程执行以下 Linux 命令:

ls -lact --full-time /etc |awk 'END {print ,,}'

在程序中,我有以下内容:

command := ' ls -lact --full-time /etc |awk \'\END {print ,,}  ';

变量command当然是事先声明的。

我得到的错误是这样的:

Encountered the symbol "\" when expecting one of the following

如能协助解决此问题,我将不胜感激。

您可以将字符串值中的单引号加倍转义:

command := 'ls -lact --full-time /etc |awk ''END {print ,,}''';

或者更干净一点,因为您不必修改原始文本(假设 Forms 支持这个!?)使用 the alternative quoting mechanism:

command := q'[ls -lact --full-time /etc |awk 'END {print ,,}']';

这里我使用 [] 作为分隔符,但它们可以是任何未出现在实际字符串中的字符:

If the opening quote_delimiter is one of [, {, <, or (, then the closing quote_delimiter must be the corresponding ], }, >, or ). In all other cases, the opening and closing quote_delimiter must be the same character.