带有换行符的Oracle SQL VARCHAR列

时间:2014-08-08 20:49:00

标签: oracle plsql

我试过了:

update MESSAGE set TEXT = 'The following ' || CHAR(13) || CHAR(10) || 'has been disapproved'
        where TITLE = 'REQUEST_DISAPPROVED';commit;

DECLARE
   msg VARCHAR2 := 'The following ' || CHAR(13) || CHAR(10) || 'has been disapproved';
BEGIN
   update MESSAGE set TEXT = :msg
            where TITLE = 'REQUEST_DISAPPROVED';
END;

var this_is_a_variable varchar2(3000); 

exec :this_is_a_variable := 'The following ' || CHAR(13) || CHAR(10) || 'has been disapproved';
update MESSAGE set TEXT = :this_is_a_variable where TITLE = 'REQUEST_DISAPPROVED';

每个都会出现各种错误,我相信这只是一个语法问题。 最终目标是当从此消息生成纯文本电子邮件时,它将适当地放置换行符。

这可能吗?

3 个答案:

答案 0 :(得分:6)

您需要使用CHR功能,新行字符会产生所需的结果。

UPDATE MESSAGE
SET TEXT = 'The following '
  || CHR(10)
  || CHR(10)
  || 'has been disapproved'
WHERE TITLE = 'REQUEST_DISAPPROVED';
COMMIT;

答案 1 :(得分:3)

您遇到语法错误。它是CHR(10)而非CHAR(10)

答案 2 :(得分:-1)

同意上述答案,其语法错误CHAR(10)功能不正确,请改用CHR(10):

例如。

SELECT 'The following ' || CHR(10) || CHR(10)|| 'has been disapproved' SMS_TEXT
FROM dual;