create or replace FUNCTION RETURN_AP_ORDER_CUR (count_product OUT NOCOPY SYS_REFCURSOR)
RETURN SYS_REFCURSOR
AS
APP_RECORDSET SYS_REFCURSOR;
i AP_ORDER%ROWTYPE;
BEGIN
OPEN APP_RECORDSET FOR
SELECT ORDER_ID,REGEXP_REPLACE(PRODUCT_NAME, '^\s', '') PRODUCT_NAME
FROM
(
SELECT a.ORDER_ID, b.COLUMN_VALUE as PRODUCT_NAME
FROM (SELECT ORDER_ID, PRODUCT_NAME FROM AP_ORDER) a
NATURAL JOIN TABLE(FNC_COL2ROW(PRODUCT_NAME)) b
);
RETURN APP_RECORDSET;
LOOP
FETCH APP_RECORDSET INTO i;
EXIT WHEN APP_RECORDSET%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(i.ORDER_ID||' '||i.PRODUCT_NAME);
INSERT INTO AP_ORDER_SPLIT (ORDER_ID,PRODUCT_NAME) VALUES (i.ORDER_ID,i.PRODUCT_NAME);
COMMIT;
END LOOP;
close APP_RECORDSET;
OPEN count_product FOR Select ORDER_ID,COUNT(1) from AP_ORDER_SPLIT group by ORDER_ID;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
dbms_output.put_line('**Error** Several Values'); -- do something meaningful here
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('There is no data in variable');
WHEN OTHERS THEN
dbms_output.put_line('Error code ' || SQLCODE || SQLERRM);
END RETURN_AP_ORDER_CUR;
使用绑定变量如何在 SQL 开发人员中获取输出参数和返回值的结果。
请分享我一个匿名块请提出一些方法
- 将逗号分隔值存储到 ref-cursor
- 在sql语句中使用函数来获取分隔值
- 获取计数数据到输出参数