http://wenku.baidu.com/link?url=MnYX269RBqW9ZRh-4famwduhYq9As0-vsIyVPA7aqv64cdxxjZEOaEE1_KZ9SGjY9qCxYIb-Fuh12pN05eZDBifBvwv5tReqjNMfZyMhW3W
TYPE CURTYPE IS REF CURSOR;
TYPE C_ATTACHED_RECORD IS RECORD(
ROW_NUM NUMBER,
PK1_VALUE NUMBER,
USER_ENTITY_NAME VARCHAR2(1000),
TITLE VARCHAR2(1000),
FILE_NAME VARCHAR2(1000),
DATATYPE_NAME VARCHAR2(1000),
FILE_DATA BLOB,
FILE_ID NUMBER);
----------------------------------------------------------------------------------
--功能名称:
-- GET_ATTACHED_HTML
--功能说明:
-- 获取附件列表html代码
--参数说明:
-- PITEM_TYPE 工作流代码
-- P_ITEM_KEY 审批关键字
-- P_FUNCTION_NAME 附件功能名称
-- P_ENTITY_NAME 文档实体标识
-- P_TABLE_NAME 文档实体表
-- p_BLOCK_NAME 附件功能的块名
-- 返回附件列表的HTML代码
--版本信息:
-- 1.0 Initial Creation
----------------------------------------------------------------------------------
FUNCTION GET_ATTACHED_HTML(PITEM_TYPE IN VARCHAR2,
PITEM_KEY IN VARCHAR2,
P_FUNCTION_NAME IN VARCHAR2,
P_ENTITY_NAME IN VARCHAR2,
P_TABLE_NAME IN VARCHAR2,
p_BLOCK_NAME IN VARCHAR2) RETURN VARCHAR2;
----------------------------------------------------------------------------------
--功能名称:
-- GET_OUTPUT_URL
--功能说明:
-- 获取附件下载链接地址
--参数说明:
-- P_PK1_VALUE 附件的主关键字值
-- P_FILE_ID 附件文件ID
-- P_ENTITY_NAME 文档实体标识
-- 返回指定附件文件的下载链接地址
--版本信息:
-- 1.0 Initial Creation
----------------------------------------------------------------------------------
FUNCTION GET_OUTPUT_URL(P_PK1_VALUE IN NUMBER,
P_FILE_ID IN NUMBER,
P_ENTITY_NAME IN VARCHAR2) RETURN VARCHAR2;
/
----------------------------------------------------------------------------------
--功能名称:
-- GET_ATTACHED_HTML
--功能说明:
-- 获取附件列表html代码
--参数说明:
-- PITEM_TYPE 工作流代码
-- P_ITEM_KEY 审批关键字
-- P_FUNCTION_NAME 附件功能名称
-- P_ENTITY_NAME 文档实体标识
-- P_TABLE_NAME 文档实体表
-- p_BLOCK_NAME 附件功能的块名
-- 返回附件列表的HTML代码
--版本信息:
-- 1.0 Initial Creation
----------------------------------------------------------------------------------
FUNCTION GET_ATTACHED_HTML(PITEM_TYPE IN VARCHAR2,
PITEM_KEY IN VARCHAR2,
P_FUNCTION_NAME IN VARCHAR2,
P_ENTITY_NAME IN VARCHAR2,
P_TABLE_NAME IN VARCHAR2,
P_BLOCK_NAME IN VARCHAR2) RETURN VARCHAR2 IS
C_ATTACHED CURTYPE;
V_DOCUMENT_ATTACHED VARCHAR2(32000);
VATTACHEDINFO C_ATTACHED_RECORD;
V_COUNT NUMBER := 1;
V_PK1_VALUE NUMBER;
VPK1_FILED VARCHAR2(61);
VPK2_FILED VARCHAR2(61);
VPK3_FILED VARCHAR2(61);
VPK4_FILED VARCHAR2(61);
VPK5_FILED VARCHAR2(61);
VPK1 VARCHAR2(61);
VPK2 VARCHAR2(61);
VPK3 VARCHAR2(61);
VPK4 VARCHAR2(61);
VPK5 VARCHAR2(61);
VURL VARCHAR2(500);
VCONDITION_FIELD VARCHAR2(100);
VCONDITION_OPERATOR VARCHAR2(10);
VCONDITION_VALUE1 VARCHAR2(100);
VCONDITION_VALUE2 VARCHAR2(100);
VQUERY_PERMISSION_TYPE VARCHAR2(10);
VINSERT_PERMISSION_TYPE VARCHAR2(10);
VUPDATE_PERMISSION_TYPE VARCHAR2(10);
VDELETE_PERMISSION_TYPE VARCHAR2(10);
V_SQL VARCHAR2(32000);
C_SQL VARCHAR2(32000);
BEGIN
BEGIN
SELECT ABE.PK1_FIELD,
ABE.PK2_FIELD,
ABE.PK3_FIELD,
ABE.PK4_FIELD,
ABE.PK5_FIELD,
ABE.CONDITION_FIELD,
ABE.CONDITION_OPERATOR,
ABE.CONDITION_VALUE1,
ABE.CONDITION_VALUE2,
ABE.QUERY_PERMISSION_TYPE,
ABE.INSERT_PERMISSION_TYPE,
ABE.UPDATE_PERMISSION_TYPE,
ABE.DELETE_PERMISSION_TYPE
INTO VPK1_FILED,
VPK2_FILED,
VPK3_FILED,
VPK4_FILED,
VPK5_FILED,
VCONDITION_FIELD,
VCONDITION_OPERATOR,
VCONDITION_VALUE1,
VCONDITION_VALUE2,
VQUERY_PERMISSION_TYPE,
VINSERT_PERMISSION_TYPE,
VUPDATE_PERMISSION_TYPE,
VDELETE_PERMISSION_TYPE
FROM FND_ATTACHMENT_BLK_ENTITIES ABE,
FND_ATTACHMENT_BLOCKS AB,
FND_ATTACHMENT_FUNCTIONS AF
WHERE ABE.ATTACHMENT_BLK_ID = AB.ATTACHMENT_BLK_ID
AND AB.ATTACHMENT_FUNCTION_ID = AF.ATTACHMENT_FUNCTION_ID
AND AF.FUNCTION_NAME = P_FUNCTION_NAME
AND AF.FUNCTION_TYPE = 'F'
AND ABE.DATA_OBJECT_CODE = P_ENTITY_NAME
AND AB.BLOCK_NAME = P_BLOCK_NAME
AND ROWNUM = 1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
SELECT ABE.PK1_FIELD,
ABE.PK2_FIELD,
ABE.PK3_FIELD,
ABE.PK4_FIELD,
ABE.PK5_FIELD,
ABE.CONDITION_FIELD,
ABE.CONDITION_OPERATOR,
ABE.CONDITION_VALUE1,
ABE.CONDITION_VALUE2,
ABE.QUERY_PERMISSION_TYPE,
ABE.INSERT_PERMISSION_TYPE,
ABE.UPDATE_PERMISSION_TYPE,
ABE.DELETE_PERMISSION_TYPE
INTO VPK1_FILED,
VPK2_FILED,
VPK3_FILED,
VPK4_FILED,
VPK5_FILED,
VCONDITION_FIELD,
VCONDITION_OPERATOR,
VCONDITION_VALUE1,
VCONDITION_VALUE2,
VQUERY_PERMISSION_TYPE,
VINSERT_PERMISSION_TYPE,
VUPDATE_PERMISSION_TYPE,
VDELETE_PERMISSION_TYPE
FROM FND_ATTACHMENT_BLK_ENTITIES ABE,
FND_ATTACHMENT_BLOCKS AB,
FND_ATTACHMENT_FUNCTIONS AF
WHERE ABE.ATTACHMENT_BLK_ID = AB.ATTACHMENT_BLK_ID
AND AB.ATTACHMENT_FUNCTION_ID = AF.ATTACHMENT_FUNCTION_ID
AND AF.FUNCTION_NAME = P_FUNCTION_NAME
AND AF.FUNCTION_TYPE = 'O'
AND ABE.DATA_OBJECT_CODE = P_ENTITY_NAME
AND AB.BLOCK_NAME = P_BLOCK_NAME
AND ROWNUM = 1;
END;
V_SQL := 'SELECT ' || SUBSTR(VPK1_FILED,
INSTR(VPK1_FILED, '.', 1) + 1,
LENGTH(VPK1_FILED)) || ' FROM ' ||
P_TABLE_NAME || ' WHERE ITEM_KEY = ''' || PITEM_KEY || '''' ||
' AND ROWNUM = 1';
EXECUTE IMMEDIATE V_SQL
INTO V_PK1_VALUE;
V_DOCUMENT_ATTACHED := '<table width=100% border="0" cellspacing="0" cellpadding="0" >
<tr><td><table cellpadding="0" cellspacing="0" border="0" width="100%" class="x74" style="background-image:url(/OA_HTML/cabo/images/swan/headingBarBg.gif);">
<tr>
<td width="100%"><h2 class="x75">附件列表</h2></td></tr></table></td></tr>
<tr><td><table width="100%" class="x1h" cellpadding="1" cellspacing="0" summary="Action History" border="1" >
<tr>
<th class="x1r x4j" scope="col" width="2%" align="LEFT" valign="baseline" ><span class="x24">序号</span></th>
<th class="x1r x4j" scope="col" width="5%" align="LEFT" valign="baseline" ><span class="x24">实体名</span></th>
<th class="x1r x4j" scope="col" width="10%" align="LEFT" valign="baseline" ><span class="x24">标题</span></th>
<th class="x1r x4j" scope="col" width="15%" align="LEFT" valign="baseline" ><span class="x24">文件名</span></th>
</tr>';
C_SQL := 'SELECT ROWNUM ROW_NUM,
PK1_VALUE,
USER_ENTITY_NAME,
TITLE,
FILE_NAME,
DATATYPE_NAME,
FILE_DATA,
FILE_ID
FROM (SELECT FAD.PK1_VALUE,
FAD.USER_ENTITY_NAME,
FAD.TITLE,
FAD.FILE_NAME,
FAD.DATATYPE_NAME,
FL.FILE_DATA,
FL.FILE_ID
FROM FND_ATTACHED_DOCS_FORM_VL FAD, FND_LOBS FL
WHERE FAD.MEDIA_ID = FL.FILE_ID
AND FAD.FUNCTION_NAME = ''' ||
P_FUNCTION_NAME ||''''||
' AND FAD.PK1_VALUE IN ' ||
'(SELECT T.' ||
SUBSTR(VPK1_FILED,
INSTR(VPK1_FILED, '.', 1) + 1,
LENGTH(VPK1_FILED)) ||
' FROM ' || P_TABLE_NAME ||
' T WHERE T.ITEM_KEY = ''' ||
PITEM_KEY || '''' || ')
AND FAD.ENTITY_NAME = '''||P_ENTITY_NAME||''''
||' ORDER BY FAD.USER_ENTITY_NAME, FAD.SEQ_NUM)';
OPEN C_ATTACHED FOR C_SQL;
FETCH C_ATTACHED
INTO VATTACHEDINFO;
WHILE C_ATTACHED%FOUND LOOP
V_DOCUMENT_ATTACHED := V_DOCUMENT_ATTACHED ||
'<tr>
<td align="LEFT" valign="baseline" class="x1l x4x">' ||
V_COUNT ||
'</td>
<td align="LEFT" valign="baseline" class="x1l x4x">' ||
VATTACHEDINFO.USER_ENTITY_NAME ||
'</td>
<td align="LEFT" valign="baseline" class="x1l x4x">' ||
VATTACHEDINFO.TITLE || '</td>
<td align="LEFT" valign="baseline" class="x1l x4x">
<a href="' ||
GET_OUTPUT_URL(V_PK1_VALUE,
VATTACHEDINFO.FILE_ID,
P_ENTITY_NAME) || '">' ||
VATTACHEDINFO.FILE_NAME || '</a></td>
</tr>';
V_COUNT := V_COUNT + 1;
FETCH C_ATTACHED
INTO VATTACHEDINFO;
END LOOP;
V_DOCUMENT_ATTACHED := V_DOCUMENT_ATTACHED ||
'</table></td></tr></table>';
RETURN V_DOCUMENT_ATTACHED;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END GET_ATTACHED_HTML;
----------------------------------------------------------------------------------
--功能名称:
-- GET_OUTPUT_URL
--功能说明:
-- 获取附件下载链接地址
--参数说明:
-- P_PK1_VALUE 附件的主关键字值
-- P_FILE_ID 附件文件ID
-- P_ENTITY_NAME 文档实体标识
-- 返回指定附件文件的下载链接地址
--版本信息:
-- 1.0 Initial Creation
----------------------------------------------------------------------------------
/*FUNCTION GET_OUTPUT_URL(P_PK1_VALUE IN NUMBER, P_FILE_ID IN NUMBER,P_ENTITY_NAME IN VARCHAR2)
RETURN VARCHAR2 IS
P_ACCESS_ID NUMBER;
V_OUTPUT_URL VARCHAR2(10000);
BEGIN
V_OUTPUT_URL := '';
SELECT ACCESS_ID
INTO P_ACCESS_ID
FROM FND_LOB_ACCESS
WHERE FILE_ID = P_FILE_ID;
V_OUTPUT_URL := RPT_REG_PKG.G_XML_PATH\*是一个配置文件值可以自己定义修改,值如:http://db1.dtpower.zszy.com:8001\*\ ||
'OA_HTML/fndgfm.jsp?mode=download_blob&fid=' ||
P_FILE_ID || '&accessid=' || P_ACCESS_ID;
RETURN V_OUTPUT_URL;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO FND_LOB_ACCESS
(ACCESS_ID, FILE_ID, TIMESTAMP)
SELECT TO_NUMBER(TO_CHAR(FND_LOBS_S.NEXTVAL) ||
TO_CHAR(SYSDATE, 'SSSSS')),
D.MEDIA_ID,
SYSDATE + 1
FROM FND_ATTACHED_DOCUMENTS B,
FND_DOCUMENTS_TL C,
FND_DOCUMENTS D
WHERE B.DOCUMENT_ID = C.DOCUMENT_ID
AND B.DOCUMENT_ID = D.DOCUMENT_ID
AND B.PK1_VALUE = P_PK1_VALUE
AND D.MEDIA_ID = P_FILE_ID
AND B.ENTITY_NAME = P_ENTITY_NAME
AND C.LANGUAGE = 'ZHS';
COMMIT;
SELECT ACCESS_ID
INTO P_ACCESS_ID
FROM FND_LOB_ACCESS
WHERE FILE_ID = P_FILE_ID;
V_OUTPUT_URL := RPT_REG_PKG.G_XML_PATH ||
'OA_HTML/fndgfm.jsp?mode=download_blob&fid=' ||
P_FILE_ID || '&accessid=' || P_ACCESS_ID;
RETURN V_OUTPUT_URL;
WHEN OTHERS THEN
P_ACCESS_ID := 0;
V_OUTPUT_URL := '';
XZTZ_LOG_PKG.INSERT_LOG('附件列表文件下载链接生成异常',
SQLERRM,
'XZ_PO_PUB_PKG.GET_OUTPUT_URL',
30);
RETURN V_OUTPUT_URL;
END GET_OUTPUT_URL;*/
FUNCTION GET_OUTPUT_URL(P_PK1_VALUE IN NUMBER,
P_FILE_ID IN NUMBER,
P_ENTITY_NAME IN VARCHAR2) RETURN VARCHAR2 IS
P_ACCESS_ID NUMBER;
V_OUTPUT_URL VARCHAR2(10000);
BEGIN
/* V_SQL_STR := 'SELECT d.file_name,d.media_id ,a.access_id,
fnd_gfm.construct_download_url(fnd_web_config.gfm_agent,d.media_id) URL ' ||
' from fnd_attached_documents b,fnd_documents_tl c,fnd_lob_access a,fnd_documents d' ||
' where b.document_id=c.document_id and b.document_id=d.document_id and b.pk1_value=''' ||
V_PK1_VALUE || '''' ||
' and a.file_id=d.media_id and b.entity_name IN (''XZ_PO_EXPENDED'',''XZ_PO_EXPENDED'')
and C.LANGUAGE=''ZHS'' '; */
V_OUTPUT_URL := FND_GFM.CONSTRUCT_DOWNLOAD_URL(FND_WEB_CONFIG.GFM_AGENT, /*应用产品 Web 代理配置文件值:http://db1.dtpower.zszy.com:8001/pls/TEST*/
P_FILE_ID);
RETURN V_OUTPUT_URL;
EXCEPTION
WHEN OTHERS THEN
P_ACCESS_ID := 0;
V_OUTPUT_URL := '';
XZTZ_LOG_PKG.INSERT_LOG('附件列表文件下载链接生成异常',
SQLERRM,
'XZ_PO_PUB_PKG.GET_OUTPUT_URL',
30);
RETURN V_OUTPUT_URL;
END GET_OUTPUT_URL;
最终效果: