2017-12-06 15 views
0

Ich kann diesen SQL Server-Code nicht in Oracle-Code konvertieren. Ich bin kein SQL-Experte, kann jemand helfen, diesen Code in Oracle-kompatibel zu konvertieren.SQL Server zu Oracle-Konvertierung

Declare @lvl as int 
Declare @rows as int 
DECLARE @foo as Table(
    KV_MANAGERNR int, 
    KV_PERSONNR varchar(10), 
    ord int, 
    lvl int) 

INSERT @foo (KV_MANAGERNR, KV_PERSONNR, ord, lvl) 
select KV_MANAGERNR, KV_PERSONNR, row_number() over(order by KV_PERSONNR), 0 
    from PERSONSMANAGER where KV_MANAGERNR='127723' 

set @[email protected]@ROWCOUNT 
set @lvl=0 

--Do recursion 
WHILE @rows > 0 
BEGIN 
    set @lvl = @lvl + 1 

    INSERT @foo (KV_MANAGERNR, KV_PERSONNR, ord, lvl) 
    SELECT DISTINCT b.KV_MANAGERNR, b.KV_PERSONNR, row_number() over(order 
    by b.KV_PERSONNR), @lvl 
    FROM PERSONSMANAGER b 
    inner join @foo f on b.KV_MANAGERNR = f.KV_PERSONNR 
    --might be multiple paths to this recursion so eliminate duplicates 
    left join @foo dup on dup.KV_PERSONNR = b.KV_PERSONNR 
    WHERE f.lvl = @lvl-1 and dup.KV_PERSONNR is null 

    set @[email protected]@ROWCOUNT 
END 

SELECT DISTINCT KV_PERSONNR from @foo order by KV_PERSONNR 
+0

Welche Fehler (e) erhalten Sie? – SchmitzIT

+0

In Zeile 1 und 2 Syntaxfehler beim Deklarieren dieser Variablen. und viele weitere Fehler –

+0

Haben Sie versucht, herauszufinden, wie Variablen in Oracle deklariert werden? Es dauert 1 Google-Suche zu finden, dass es eine andere Syntax als SQL Server verwendet. Mein Vorschlag ist, dass Sie beginnen, Fehler 1 zu 1 zu lösen. Sie werden wahrscheinlich in den nächsten Fehler stoßen. Wenn Sie damit nicht weiterkommen, können Sie jederzeit eine neue Frage mit einer bestimmten Anfrage stellen. Gerade jetzt scheint es, als ob Sie einfach wollen, dass jemand den Code für Sie übersetzt. SO ist dafür nicht gedacht. Wir helfen Ihnen gerne bei spezifischen Problemen, erwarten aber, dass Sie einige Anstrengungen von Ihrer Seite erwarten. – SchmitzIT

Antwort

0
DECLARE 
    v_lvl Number:=0; 
    v_rows number:=1; 
BEGIN 
    INSERT INTO nt_list_0 (KV_MANAGERNR, KV_PERSONNR, ord, lvl) 
     select KV_MANAGERNR, KV_PERSONNR, row_number() over(order by 
     KV_PERSONNR), 0 from PERSONSMANAGER where KV_MANAGERNR='100047'; 

    WHILE v_rows>0 
    LOOP 
     v_lvl := v_lvl +1; 

     INSERT INTO nt_list_0 (KV_MANAGERNR, KV_PERSONNR, ord, lvl) 
     SELECT DISTINCT b.KV_MANAGERNR, b.KV_PERSONNR, row_number() 
      over(order by b.KV_PERSONNR), v_lvl 
     FROM PERSONSMANAGER b 
     inner join nt_list_0 f on b.KV_MANAGERNR = f.KV_PERSONNR 
     left join nt_list_0 dup on dup.KV_PERSONNR = b.KV_PERSONNR 
     WHERE f.lvl = v_lvl-1 and dup.KV_PERSONNR is null; 

     v_rows := sql%rowcount; 
    END LOOP; 
END;