我们需要在表中存储select语句
select * from table where col = 'col'
Run Code Online (Sandbox Code Playgroud)
但单引号混淆了插入语句.
有可能以某种方式这样做吗?
从Oracle 10G开始,可以选择将单引号加倍:
insert into mytable (mycol) values (q'"select * from table where col = 'col'"');
Run Code Online (Sandbox Code Playgroud)
我使用双引号字符("),但你可以指定一个不同的字符,例如:
insert into mytable (mycol) values (q'@select * from table where col = 'col'@');
Run Code Online (Sandbox Code Playgroud)
文字的语法是:
q'<special character><your string><special character>'
Run Code Online (Sandbox Code Playgroud)
在这样的小例子中,它显然不具有可读性,但它可以获得大量文本,例如
insert into mytable (mycol) values (
q'"select empno, ename, 'Hello' message
from emp
where job = 'Manager'
and name like 'K%'"'
);
Run Code Online (Sandbox Code Playgroud)