如何將此代碼轉換爲具有相同輸出的函數?通過代碼塊創建功能
declare
record_name employees%ROWTYPE;
begin
FOR record_name IN (SELECT (a.first_name || ' ' || a.last_name) complete_name,
b.DEPARTMENT_NAME complete_name2
FROM employees a , departments b
WHERE ROWNUM < 1000 and a.DEPARTMENT_ID=b.DEPARTMENT_ID)
LOOP
DBMS_OUTPUT.PUT_LINE('Employee name: ' || record_name.complete_name
||'DEPARTMENT name: '||record_name.complete_name2);
END LOOP;
END;
你只想打印還是希望函數返回記錄集以便進一步操作?對於前者,請使用@Sajmon給出的答案,用Put_Line替換累積級聯。對於後者,您需要創建一個表值函數。 – SQLCurious