2016-06-16 4 views
0

Ich habe eine PL \ SQL, die einen Datensatz zurückgibt, der Volumes nach Konto || Produkt in zwei verschiedenen Tabellen im Wesentlichen überprüft.Einrichten von SYS_REFCURSOR in PL SQL, um das Dataset zurückzugeben

Mein Endziel ist es, diesen Datensatz direkt in eine Kalkulationstabelle (mit Excel-VBA) durch Übergabe von Datumsparametern (bereitgestellt durch Excel) und Aufruf der Stored-Procedure ziehen zu lassen.

Nach dem Lesen ein wenig auf PL \ SQL scheint es, dass ich eine Cursor-Variable zum Speichern der Endergebnis-Datei, die zur Verfügung gestellt wird, so kann ich dann in die Tabelle (als Recordset) schreiben.

Die folgenden Beispiele online, ich habe meine Prozedur geschrieben wie so

CREATE OR REPLACE PROCEDURE PROC_REG_SPLIT_RECON (dStart IN Date, dEnd IN Date) 
-- procedure to check regional splits creation is okay 
-- procedure checks volumes by account and product from FACT_TRADE_PRESPLIT_ROLLUP to FACT_TRADE_ROLLUP 

-- SQLDeveloper doesn't like this section and I can't figure out how to set this up correctly, no matter what I do and research. 

RETURN SYS_REFCURSOR 
AS 
l_return SYS_REFCURSOR; 
-- end of section not working 

BEGIN 

OPEN l_return FOR 

    SELECT OpStats.Account, OpStats.Platform, OpStats.Volume OpStatsVol, RegSplits.Volume RegSplitsVol, (OpStats.Volume-RegSplits.Volume) Difference FROM 

    (a bunch of union queries) OpStats, 

    (a bunch of other union queries) RegSplits 

WHERE OpStats.Account = RegSplits.Account (+) And OpStats.Platform = RegSplits.Platform (+) 
ORDER BY OpStats.Account ASC, OPStats.Platform DESC; 

RETURN l_return; 

END; 

FWIW, arbeiten die Abfragen Fein- und Ergebnisse zurück wie erwartet. Weiß jemand, warum mein PL \ SQL nicht kompiliert? Oder wenn ich in meinem Ansatz weit weg bin?

Antwort

1

Versuchen Funktion als Return-Anweisung der Erstellung nur in fucntion verwendet wird. Die RETURN-Anweisung in PROCEDURE wird nur verwendet, um den Vorgang normalerweise an der gewünschten Position zu beenden. Hoffnung unter Code hilft.

CREATE OR REPLACE FUNCTION PROC_REG_SPLIT_RECON(--Function has to be incorporated 
    dStart IN DATE, 
    dEnd IN DATE) 
    -- procedure to check regional splits creation is okay 
    -- procedure checks volumes by account and product from FACT_TRADE_PRESPLIT_ROLLUP to FACT_TRADE_ROLLUP 
    -- SQLDeveloper doesn't like this section and I can't figure out how to set this up correctly, no matter what I do and research. 
    RETURN SYS_REFCURSOR 
AS 
    l_return SYS_REFCURSOR; 
    -- end of section not working 
BEGIN 
    OPEN l_return FOR SELECT OpStats.Account, OpStats.Platform, OpStats.Volume OpStatsVol, RegSplits.Volume RegSplitsVol, (OpStats.Volume-RegSplits.Volume) Difference FROM (a bunch OF 
    UNION queries) OpStats, (a bunch OF other 
    UNION queries) RegSplits WHERE OpStats.Account = RegSplits.Account (+) AND OpStats.Platform = RegSplits.Platform (+) ORDER BY OpStats.Account ASC, OPStats.Platform DESC; 
    RETURN l_return; 
END; 
2

Sie erstellen eine Oracle-Prozedur und eine Prozedur kann kein RETURN-Schlüsselwort mit einem angegebenen Rückgabedatentyp haben. Erstellen Sie eine Oracle-Funktion, um das zu tun, was Sie tun möchten.

CREATE OR REPLACE FUNCTION FUN_REG_SPLIT_RECON 
... 
RETURN SYS_REFCURSOR 
....