我成功获取了我需要的数据,但我希望将结果作为连续字符串分隔,这是我的示例代码
CONNECT mgs/mgs;
SET SERVEROUTPUT ON;
DECLARE
CURSOR PRODUCT_SUMMARY_CURSOR IS
SELECT PRODUCT_NAME ,LIST_PRICE FROM PRODUCTS
ORDER BY LIST_PRICE DESC;
PRODUCT_SUMMARY_ROW PRODUCTS%ROWTYPE;
BEGIN
FOR PRODUCT_SUMMARY_ROW IN PRODUCT_SUMMARY_CURSOR LOOP
IF (PRODUCT_SUMMARY_ROW.LIST_PRICE > 700) THEN
DBMS_OUTPUT.PUT_LINE ('"' || PRODUCT_SUMMARY_ROW.PRODUCT_NAME || '",' || '"' || PRODUCT_SUMMARY_ROW.LIST_PRICE || '"' || '|');
END IF;
END LOOP;
END;
/
答案 0 :(得分:1)
根据您要处理的产品数量,以下内容应该有效。如果字符串变长,那么您可能需要查看使用clob而不是varchar2。
CONNECT mgs/mgs;
SET SERVEROUTPUT ON;
DECLARE
v_output_string varchar2(4000) default null;
CURSOR PRODUCT_SUMMARY_CURSOR IS
SELECT PRODUCT_NAME ,LIST_PRICE FROM PRODUCTS
ORDER BY LIST_PRICE DESC;
PRODUCT_SUMMARY_ROW PRODUCTS%ROWTYPE;
BEGIN
FOR PRODUCT_SUMMARY_ROW IN PRODUCT_SUMMARY_CURSOR LOOP
IF (PRODUCT_SUMMARY_ROW.LIST_PRICE > 700) THEN
v_output_string := v_output_string || '"' || PRODUCT_SUMMARY_ROW.PRODUCT_NAME || '",' || '"' || PRODUCT_SUMMARY_ROW.LIST_PRICE || '"' || '|';
END IF;
END LOOP;
dbms_output.put_line(v_output_string);
END;
/