Announcement

Collapse
No announcement yet.

Stored Procedure ausführen ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stored Procedure ausführen ?

    Guten Tag!

    Ich komme irgendwie nicht weiter, wie führt mal in Oracle eine Procedure aus? Z.B. dises, mit folgendem Rumpf:

    procedure nun (tag OUT DATE)
    AS
    begin
    tag := sysdate;
    end;

    Bin für jede Hilfe dankbar!

    Gruß RAlf

  • #2
    Hi!

    Du kannst eine Procedur innerhalb
    eines anonymen plsql-Blockes,einer
    anderen Procedur,Function
    oder Package.

    Anonymer Block
    Beispeil :

    declare
    V_ak_datum date;

    begin
    nun (V_ak_datum);
    dbms_output.put_line('Tag: ' || to_char (V_ak_datum , 'DD.MM.YYYY'));
    end;

    Functionen kann man auch in einer Selektion
    aufrufen:

    Beispiel:

    create function f_nun
    return date
    as
    begin
    return sysdate;
    end;

    Aufruf:
    select f_nun from dual;

    Um halbwegs komfortabel
    Proceduren,Functions etc. zu schreiben
    solltest du dir eine gutes Tool wie den
    SQL Navigator oder das (für privaten Einsatz) kostenlose
    Tora anschaffen.
    SQL-Navigator: http://www.quest.com
    Tora: http://www.globecom.se/tora/

    Gruß
    Michae

    Comment


    • #3
      danke für den Hinweis

      Comment


      • #4
        Und wenn man etwas dynamisches will, dann kann man auch<br><br>EXECUTE IMMEDIATE statement;<br><br>verwenden. In der Doku gibt es sehr gute Beispiele, wie man auch Parameter in das Statement parsen kann.

        Dietma

        Comment


        • #5
          Ich habe folgenden Pecedure:
          Code:
          create or replace
          PROCEDURE Warenentnahme
            (warid in INTEGER, menge in INTEGER)
          as
            minanz integer;
            anz integer;
          begin
            UPDATE lager set anzahl = anzahl - menge WHERE warenid = warid;
            SELECT w.mindestvorratsmenge, l.anzahl INTO minanz, anz FROM lager l join ware w on w.warenid = warid;
            if minanz > anz then
              Update lager set anzahl = anzahl + 50 where warenid = warid;
            end if;
          end;
          Wenn ich diese ausführe mit:
          Code:
          begin
          exec Warenentnahme(5,2);
          end;
          /
          Sagt er mir : PLS-00103 Fand das Symbol "WARENENTNAHME" als eines der folgenden erwartet wurde:
          :=.(@%;

          Kann mir jemand sagen wo mein Problem liegt?

          Comment


          • #6
            exec ist ein sqlplus Befehl, der intern nichts anderes macht als ein begin - end um den Aufruf zu schreiben. Es handelt sich also um einen reinen Client Befehl.

            Lass das exec einfach weg, dann läufts.

            Dim
            Zitat Tom Kyte:
            I have a simple philosophy when it comes to the Oracle Database: you can treat it as a black box and just stick data into it, or you can understand how it works and exploit it as a powerful computing environment.

            Comment


            • #7
              Vielen dank, du weisst anscheinend auf alles eine Antwort. Aber sollte es dann nicht auch gehen wenn ich...
              exec Warenentnahme(5,2);
              ...ohne das begin und end schreibe? Tut es nämlich nicht.

              Comment


              • #8
                Das exec ist wie gesagt ein reiner Clientbefehl. Wenn du sqlplus verwendest, dann geht es. Andere Programme müssen diesen Befehl nicht unterstützen. Es ist kein Oraclebefehl.

                Dim
                Zitat Tom Kyte:
                I have a simple philosophy when it comes to the Oracle Database: you can treat it as a black box and just stick data into it, or you can understand how it works and exploit it as a powerful computing environment.

                Comment

                Working...
                X