简体   繁体   English

串联问题 - 使用html和SYS_REFCURSOR的Oracle Email

[英]Issue in concatenation - Oracle Email using html and SYS_REFCURSOR

I am new to oracle and trying to send mail using UTL_MAIL.SEND . 我是oracle的新手并尝试使用UTL_MAIL.SEND发送邮件。 I am using HTML in between to create table and all. 我在中间使用HTML来创建表和所有。 Using a CLOB variable to store the HTML and SYS_REFCURSOR to store the query result. 使用CLOB变量存储HTMLSYS_REFCURSOR以存储查询结果。 Inside the query trying to fetch data from SYS_REFCURSOR using loop. 在查询内部尝试使用循环从SYS_REFCURSOR获取数据。 All the structure is coming fine, but values inside HTML table ie fetching from SYS_REFCURSOR two hash(#) is appended to last value. 所有结构都很好,但HTML表格中的值即从SYS_REFCURSOR获取两个哈希(#)附加到最后一个值。 My query is as follows. 我的查询如下。

DECLARE postComments SYS_REFCURSOR;
v_Message CLOB;

liscname DAN_DANAPP_TRADE_LIC.OTL_LIC_NAME%TYPE;

lisctype DAN_DANAPP_TRADE_LIC.OTL_LIC_TYPE%TYPE;

authority DAN_DANAPP_TRADE_LIC.OTL_LIC_AUTH%TYPE;

lastdate DAN_DANAPP_TRADE_LIC.OTL_EXPIRY_DT%TYPE;

daysrem number;

BEGIN OPEN postComments
FOR
SELECT otl.OTL_LIC_NAME,
       otl.OTL_LIC_TYPE,
       otl.OTL_LIC_AUTH,
       to_char(to_date(otl.OTL_EXPIRY_DT,'DD/MM/YYYY')) AS expirydate,
       to_date(otl.OTL_EXPIRY_DT,'dd/mm/yyyy')-to_date(sysdate,'dd/mm/yyyy') AS daystoexpire
FROM DAN_DANAPP_TRADE_LIC otl
WHERE OTL_EFF_TO_DT IS NULL
  AND (to_date(otl.OTL_EXPIRY_DT,'dd/mm/yyyy')-to_date(sysdate,'dd/mm/yyyy'))<=45
  AND OTL_CLO_STATUS=0
ORDER BY (to_date(otl.OTL_EXPIRY_DT,'dd/mm/yyyy')-to_date(sysdate,'dd/mm/yyyy')) DESC;

v_Message := q'#<html>
<body>Dear Sir/Madam,<br><br>
The following trade license(s) will expire soon. Please followup accordingly.
<br><br>
<table border="1"  width="90%">
<tr>
<th>
Company
</th>
<th>
License Type
</th>
<th>
Licensing Authority
</th>
<th>
Expiry Date
</th>
<th>
Days Left
</th>
</tr>#';

LOOP FETCH postComments INTO liscname,
                             lisctype,
                             authority,
                             lastdate,
                             daysrem;

EXIT WHEN postComments%NOTFOUND; --  dbms_output.put_line(liscname);

dbms_lob.append(v_Message, q'#<tr><td>#'|| liscname || q'#</td> 
<td>#'|| lisctype || q'#</td>
<td>#'|| authority || q'#</td>
<td>#'|| lastdate || q'#</td>
<td>#'|| daysrem || '#</td></tr>#');

END LOOP;

CLOSE postComments;

dbms_lob.append(v_Message, q'#</table>
<br><br>
<font size="2">Sent from <font color="red">DanApps</font></font>
</body>
</html>#');

UTL_MAIL.SEND(sender=>'c@xyz.com', recipients=>'a.b@xyz.com', subject=>'Trade license expiry', message => v_Message, priority => 1, mime_type => 'text/html; charset=us-ascii'); --send out emails in HTML format.

END;

Output 产量

在此输入图像描述

As you said If I put q' then format changes as follows(Sorry I couldn't provide data.) 如你所说如果我把q'然后格式更改如下(抱歉,我无法提供数据。)

Please help me to sort the issue. 请帮我解决问题。 Thanks in advance. 提前致谢。

The problem is that you are using q' as quote delimiter and are not completing it with the closing # in this line .So the variables end up interpreted as strings. 问题是,你正在使用q'作为分隔符的报价,并且不与封闭完成它#这一行。所以变量都解释为字符串。

q'#<tr><td>'|| liscname || '</td>   -- Wrong

q'#<tr><td>#'|| liscname || '</td>  -- Right

And you are terminating # in this line which is also not correct 而你在这一行终止#也是不正确的

 <td>'|| daysrem || '</td></tr>#');

In your case , since you don't have single quotes within tags, q' notation would not be required. 在您的情况下,由于您在标记中没有单引号,因此不需要q'表示法。

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

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