如何将ORACLE存储过程中SQL的结果集打印出来,并且按照一定的格式封装到一个字符串中呢
CREATEORREPLACEPROCEDUREKH.WAPCRM_CJ(V_OP_IDINNUMBER,V_MONTHINNUMBER,V_INFOOUTVARCHAR...
CREATE OR REPLACE PROCEDURE KH.WAPCRM_CJ(
V_OP_ID IN NUMBER,
V_MONTH IN NUMBER,
V_INFO OUT VARCHAR2) IS
V_SQL VARCHAR2(3000);
BEGIN
V_SQL='SELECT OBJECT_ID || ''|''||
OBJECT_NAME || ''|''||
PHASE_ID || ''|''||
BUSI_TYPE || ''|''||
BUSI_NAME || ''|''||
BUSI_SUBCLASS_CODE || ''|''||
BUSI_SUBCLASS_NAME || ''|''||
BUSI_CLASSIFI_CODE || ''|''||
BUSI_CLASSIFI_NAME || ''|''||
BRAND_TYPE || ''|''||
CODE_NAME || ''|''||
RULER_OPTI || ''|''||
RULER_CENT || ''|''||
DONE_DATE || ''|''||'';''
FROM KH.KF_IVR_BUSI_CALCULATE S WHERE S.PHASE_ID=' || V_MONTH ||
' AND S.OBJECT_ID=' || V_OP_ID || '';
V_INFO := INFO;
END WAPCRM_CJ;
简单的数就是讲查询结果集,返回,加个分隔符,最后组装个一个字符串 展开
V_OP_ID IN NUMBER,
V_MONTH IN NUMBER,
V_INFO OUT VARCHAR2) IS
V_SQL VARCHAR2(3000);
BEGIN
V_SQL='SELECT OBJECT_ID || ''|''||
OBJECT_NAME || ''|''||
PHASE_ID || ''|''||
BUSI_TYPE || ''|''||
BUSI_NAME || ''|''||
BUSI_SUBCLASS_CODE || ''|''||
BUSI_SUBCLASS_NAME || ''|''||
BUSI_CLASSIFI_CODE || ''|''||
BUSI_CLASSIFI_NAME || ''|''||
BRAND_TYPE || ''|''||
CODE_NAME || ''|''||
RULER_OPTI || ''|''||
RULER_CENT || ''|''||
DONE_DATE || ''|''||'';''
FROM KH.KF_IVR_BUSI_CALCULATE S WHERE S.PHASE_ID=' || V_MONTH ||
' AND S.OBJECT_ID=' || V_OP_ID || '';
V_INFO := INFO;
END WAPCRM_CJ;
简单的数就是讲查询结果集,返回,加个分隔符,最后组装个一个字符串 展开
3个回答
展开全部
这就用上了递归的思想,思路如下,没有你的数据如果有问题你调试下
V_SQL='select * from (
select REPLACE(SYS_CONNECT_BY_PATH(a,','),',') , LEVEL from (
SELECT OBJECT_ID || ''|''||
OBJECT_NAME || ''|''||
PHASE_ID || ''|''||
BUSI_TYPE || ''|''||
BUSI_NAME || ''|''||
BUSI_SUBCLASS_CODE || ''|''||
BUSI_SUBCLASS_NAME || ''|''||
BUSI_CLASSIFI_CODE || ''|''||
BUSI_CLASSIFI_NAME || ''|''||
BRAND_TYPE || ''|''||
CODE_NAME || ''|''||
RULER_OPTI || ''|''||
RULER_CENT || ''|''||
DONE_DATE || ''|''||'';'' a
FROM KH.KF_IVR_BUSI_CALCULATE S WHERE S.PHASE_ID=' || V_MONTH ||
' AND S.OBJECT_ID=' || V_OP_ID || ')
START WITH ROWNUM =1
CONNECT BY PRIOR rn +1= rn ORDER BY LEVEL DESC )
WHERE ROWNUM < 2 ';
V_SQL='select * from (
select REPLACE(SYS_CONNECT_BY_PATH(a,','),',') , LEVEL from (
SELECT OBJECT_ID || ''|''||
OBJECT_NAME || ''|''||
PHASE_ID || ''|''||
BUSI_TYPE || ''|''||
BUSI_NAME || ''|''||
BUSI_SUBCLASS_CODE || ''|''||
BUSI_SUBCLASS_NAME || ''|''||
BUSI_CLASSIFI_CODE || ''|''||
BUSI_CLASSIFI_NAME || ''|''||
BRAND_TYPE || ''|''||
CODE_NAME || ''|''||
RULER_OPTI || ''|''||
RULER_CENT || ''|''||
DONE_DATE || ''|''||'';'' a
FROM KH.KF_IVR_BUSI_CALCULATE S WHERE S.PHASE_ID=' || V_MONTH ||
' AND S.OBJECT_ID=' || V_OP_ID || ')
START WITH ROWNUM =1
CONNECT BY PRIOR rn +1= rn ORDER BY LEVEL DESC )
WHERE ROWNUM < 2 ';
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
利用dbms_output.put_line(),wm.concat()函数,应该可以实现你的需求
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DBMS_OUTPUT.PUT_LINE (你要的内容);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询