PL SQL examples

Hi friends,
I have learnt the PL SQL. I know syntax like how to write cursors, procedures, functions. But then, I am unable to find online few examples that I can work on, like writing procedure myself.
Is there any web link where I can find few examples on PLSQL programming so that I can get used to it?

Hi,
You can download pdf :
PL/SQL User's Guide and Reference
PL/SQL Packages and Types Reference
http://www.oracle.com/pls/db102/portal.portal_db?selected=5

Similar Messages

  • Lock types in oracle 10g with sql examples

    can some body easily in simple words tell some thing about the table locks types in oracle 10g with some sql examples?

    Oracle locking is a complex topic that may not easily be explained with simple words.
    Please try to read above mentioned link starting from simple examples to used lock types. I don't think it's a good idea to "over simplify" the topic starting from the different lock types.
    Another way to explain some lock types can be found in following OTN discussion with Tom Kyte (who is also one of the primary author of Concepts Guide 11.2): TM / TX Locks ( Tom Kyte and Oracle Docu) ; note the different points of view about what is the row lock ...
    Edited by: P. Forstmann on 29 juin 2011 14:00

  • I need one recurcive(unended loop) pl/sql example, its very urgent pls

    Hi,
    I need one recurcive (unended loop) pl/sql example, its very urgent pls
    Thanks,
    Sathis.

    I suppose you'll want to know how to get out of your undended loop too (although that does stop it being unended).
    Example...
    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2    v_cnt NUMBER := 0;
      3  BEGIN
      4    LOOP
      5      EXIT WHEN v_cnt = 1000;
      6      v_cnt := v_cnt + 1;
      7    END LOOP;
      8* END;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>

  • Any PL/SQL examples of using ICX?

    I am trying to include some static HTML into a web page that's
    generated in PL/SQL. The documentation has led me to the ICX
    module (to connect through to the LiveHTML agent) but its
    examples are in PERL which I don't know in any
    depth. I would be very grateful to anyone who can supply a
    simple example of using ICX in PL/SQL.
    Regards,
    Anthony.

    As far as I know, Artificial Intelligence has not yet been achieved, although if someone's written a PL/SQL package that can beat Gary Kasparov at chess I'd like to see it.
    My wife thought the movie was called "A One".

  • Any PL/SQL examples of using ICX in the Web Server?

    I am trying to include some static HTML into a web page that's
    generated in PL/SQL. The documentation has led me to the ICX
    module but its examples are in PERL which I don't know in any
    depth. I would be very grateful to anyone who can supply a
    simple example of using ICX in PL/SQL.
    Regards,
    Anthony.

    As far as I know, Artificial Intelligence has not yet been achieved, although if someone's written a PL/SQL package that can beat Gary Kasparov at chess I'd like to see it.
    My wife thought the movie was called "A One".

  • Contact Service Queue Activity Report (by CSQ) Report SQL example

    I've been tasked to recreate the Contact Service Queue Activity Report (by CSQ) Report, with SQL in SQL Server 2008 RS, Can someone give me an example or actual sql for this report? I've tried to folllow the hints about joining in the documentation, however, my reported numbers are much higher than what the Cisco report is giving back.
    Thanks to anybody who knows where this sql is.
    Lyle

    Hi Lyle,
    Please refer the section "Restrictions with Generating Historical Reports" in the below UCCX release notes.
    http://www.cisco.com/web/ccbu/CRS/8/0/2/SU3/UCCX_802_SU3_Relnote.pdf
    CSCtj96987 : Reports unable to generate large set of records bcz of tmp dbspace limit
    Defect Description:
    Customers are unable to generate HR reports for a larger duration because of a limitation set based on first 10k records in CCD table. Many customers require to generate reports for a complete month which they are unable to do now in 8.x
    affected reports are :
    Abandoned Call Detail
    Aborted Rejected Call Detail
    Agent Detail
    Agent Login Logout
    Agent State Detail
    Detailed Call by Call CCDR
    Detailed Call CSQ Agent
    Additional Info
    1.     Customer may get runtime error if the temp dbspace gets full. HRC log will state clearly that the system ran out of disk space. This will happen if the customer is running reports for a very large set of data or running large number of simultaneous HR sessions involving considerable amount of data.
    2.     The temp dbspace is fixed at 2GB and cannot grow automatically when required. So, if the space is filled completely, HR reports will error out. The temp dbspace will be freed when the session ends. So, If you get run time error anytime, please restart HRC and try to generate report for a smaller period of time.
    3.     It is recommended to generate reports approximately upto 200,000 rows when a single session is running to avoid getting run time errors. If multiple sessions are running, modify the figure accordingly.
    4.     If the customer is running a single node setup, it is highly recommended to generate reports in the off-peak hours.
    Fixed in :
    8.0(2)SU2,  8.5(1)SU2,  9.0(1)
    You can think of upgrading your UCCX system to the above releases for this issue fix.
    Thanks,
    Anand

  • AI-Based Solutions programmed in PL/SQL, Examples of AI

    Does any one know of some good examples of PL/SQL code used to implement AI-based problem solving?
    -I'm taking an AI course and would like to program using PL/SQL and solve database related problems
    -Any books and URL's would be much appreciated
    Thank you in advance for your kind consideration!

    As far as I know, Artificial Intelligence has not yet been achieved, although if someone's written a PL/SQL package that can beat Gary Kasparov at chess I'd like to see it.
    My wife thought the movie was called "A One".

  • Error using WebServicesAssembler to create webservice for PL/SQL-Example

    Hello all,
    I tried to create a webservice based upon the pl/sql package emptax (Oracle Example: Boolean). The package just contains:
    PACKAGE EMPTAX as
    FUNCTION getTax(employeeid number, ismarried boolean) RETURN number ;
    END Emptax;
    JAVA_HOME, ORACLE_HOME and CLASSPATH are all set according to the manual. Now I start the WebServiceAssembler.jar with:
    java      -jar C:\oracle11\product\11.1.0\db_1\oc4j\webservices\lib\WebServicesAssembler.jar
         -config C:\Daten\tmp\webservice_boolean\Boolean\config\config.xml
    The config.xml looks like this:
    <web-service>
         <destination-path>./EmpTax.ear</destination-path>
         <temporary-directory>./tmp</temporary-directory>
         <context>/webservices</context>
         <stateless-stored-procedure-java-service>
              <uri>/EmpTax</uri>
              <jar-generation>
                   <schema>scott/tiger</schema>
                   <db-url>jdbc:oracle:thin:@10.10.10.10:1521:prod11</db-url>
                   <db-pkg-name>EmpTax</db-pkg-name>
                   <prefix>EmpTax</prefix>
              </jar-generation>
              <database-JNDI-name>jdbc/prod11</database-JNDI-name>
         </stateless-stored-procedure-java-service>
    </web-service>
    The EmpTax.jar is created, containing:
    - EmpTax.java
    - EmpTaxBase.java
    - EmpTaxBase.sqlj
    - EmpTaxUser.java
    - EmpTaxUser.sqlj
    At the end, there appears the error:
         java.lang.Win32Process.create
         java.lang.Runtime.execInternal
         java.lang.Runtime.exec
         oracle.j2ee.ws.tools.WsAssemblerConfig
         => NullPointerException: class EmpTax.EmpTaxUser not found
    The EmpTax.ear-File is not generated. I'm really stuck now. Does anybody has a hint?
    Thanks in advance
    Christoph

    Ignore the last one. I did the example here over lunch and it works fine.
    http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/boolean/boolean.html
    Try the -debug and see what happens.
    When I run these tests, I always make sure that my PATH, and CLASSPATH are the absolute minimum. That is:
    SET PATH=C:\j2sdk1.4.2_10\bin
    SET CLASSPATH=.\
    SET OC4J_HOME=C:\OC4J_101202
    SET J2EE_HOME=%oracle_home%\j2ee\home
    It may just be that the classpath that you see when you run it in debug mode is missing some of the required jars for the jpub/sqlj stuff. Verify that they are all ok.
    Eric

  • Embedde SQL Examples

    Hello,
    i installed the 11.1 Database for 32 bit windows on my system.
    I want to use the embedded sql interface.
    I am missing the examples for visual Studio, the description in the documentation is for the old Studio (6.0)
    and i am not getting it to work.
    The Precompiler doesn't run correctly.
    Is it possible to display the proc.exe file statement in an output window, i only the the error.
    1>------ Erstellen gestartet: Projekt: ProcSample, Konfiguration: Debug Win32 ------
    1>Oracle Precompiler
    1>Pro*C/C++: Release 11.1.0.6.0 - Production on Di Dez 1 17:07:58 2009
    1>Copyright (c) 1982, 2007, Oracle. All rights reserved.
    1>System-Standardoptionswerte aus: c:\oracle\product\11.1.0\db_1\precomp\admin\pcscfg.cfg
    1>Optionsname Aktueller Wert Beschreibung
    1>-------------------------------------------------------------------------------
    1>auto_connect Nein Automatische Anmeldung bei Account ops$
    1> zulassen
    1>char_map charz Zuordnung von Zeichen-Arrays und Zeichenfolgen
    1>close_on_commitNein Alle Cursor bei COMMIT schlie▀en
    1>cmax 100 CMAX-Wert f³r Connection-Pool
    1>cmin 2 CMIN-Wert f³r Connection-Pool
    1>cincr 1 CINCR-Wert f³r Connection-Pool
    1>ctimeout 0 CTIMEOUT-Wert f³r Connection-Pool
    1>cnowait 0 CNOWAIT-Wert f³r Connection-Pool
    1>common_parser Nein Mit Common SQL Frontend parsen
    1>code ansi_c Der zu generierende Codetyp
    1>comp_charset multi_byte Der Zeichensatztyp, den der C Compiler
    1> unterst³tzt
    1>config default Systemkonfigurationsdatei durch andere Datei
    1> au▀er Kraft setzen
    1>cpool Nein Unterst³tzung von Connection-Pooling
    1>cpp_suffix kein Standardmõ▀iges C++ Dateinamensuffix au▀er
    1> Kraft setzen
    1>db2_array Nein Unterst³tzung von DB2 Array
    1> Insert/Select-Syntax
    1>dbms native v6/v7/v8-Kompatibilitõts-Modus
    1>def_sqlcode Nein Makro '#define SQLCODE sqlca.sqlcode'
    1> generieren
    1>define WIN32_LEAN_AND_Prõprozessor-Symbol definieren
    1>duration transaction Pin-Dauer f³r Objekte im Cache festlegen
    1>dynamic oracle Oracle oder ANSI Dynamic SQL Semantics angeben
    1>errors Ja Angabe, ob Fehlermeldungen an das Terminal
    1> gesendet werden
    1>errtype kein Name der Listendatei f³r Intype-Dateifehler
    1>events Nein Publish/Subscribe-Ereignisbenachrichtigungen
    1> unterst³tzen
    1>fips none FIPS-Flagging von nicht konformer ANSI-Nutzung
    1>header kein Dateinamenerweiterung f³r vorkompilierte Header
    1> angeben
    1>hold_cursor Nein Halten von Cursorn im Cursor-Cache
    1> kontrollieren
    1>implicit_svpt Nein Impliziter Savepoint vor gepufferter
    1> Insert-Anweisung
    1>iname kein Name der Eingabedatei
    1>include kein Verzeichnispfade f³r enthaltene Dateien
    1>intype kein Name der Eingabedatei f³r Typinformationen
    1>lines Nein #line-Anweisungen zu dem generierten Code
    1> hinzuf³gen
    1>lname kein Standard-Listendateiname au▀er Kraft setzen
    1>ltype none In der Listendatei generierte Datenmenge
    1>maxliteral 1024 Max. Lõnge des generierten
    1> Zeichenfolgenliterals
    1>maxopencursors 10 Max. Anzahl von ge÷ffneten Cursorn im Cache
    1>max_row_insert 0 Max. Anzahl von Zeilen, die in Insert-Anweisung
    1> gepuffert werden m³ssen
    1>mode oracle Code-▄bereinstimmung mit Oracle- oder
    1> ANSI-Regeln
    1>native_types Nein Unterst³tzung von systemeigenem Float/Double
    1>nls_char kein Lõnderspezifische Zeichenvariablen angeben
    1>nls_local Nein NLS-Zeichensemantik kontrollieren
    1>objects Ja Objekttypen unterst³tzen
    1>oname kein Name der Ausgabedatei
    1>oraca Nein Benutzung von ORACA kontrollieren
    1>outline no Kategorie, in der Outlines erstellt werden
    1> [yes/no/<category name>]
    1>outlnprefix kein Prõfix des Outline-Namens
    1>pagelen 80 Seitenlõnge der Listendatei
    1>parse none Kontrollieren, welcher Nicht-SQL-Code
    1> analysiert wird
    1>prefetch 1 Anzahl von Zeilen, die im Voraus beim Íffnen
    1> des Cursors (mit OPEN) abgerufen wurden
    1>release_cursor Nein Freigabe von Cursorn aus Cursor-Cache
    1> kontrollieren
    1>runoutline Nein Wenn ja, Outlines in der Datenbank erstellen
    1>select_error Ja Flagging von Select-Fehlern kontrollieren
    1>sqlcheck syntax Umfang der SQL-Pr³fung beim Kompilieren
    1>stmt_cache 0 Gr÷▀e des Anweisungs-Caches
    1>sys_include kein Verzeichnis, in dem System-Header-Dateien
    1> gespeichert sind
    1>threads Nein Gibt eine Multi-Threaded-Anwendung an
    1>type_code oracle Oracle- oder ANSI-Codes f³r Dynamic SQL
    1> verwenden
    1>unsafe_null Nein NULL-Fetch ohne Indikatorvariable zulassen
    1>userid kein Connect-String Benutzername/Kennwort [@dbname]
    1>utf16_charset nchar_charset Zeichensatz-Form, wie von UTF16-Variablen
    1> benutzt
    1>varchar Nein Benutzung von impliziten Varchar-Strukturen
    1> zulassen
    1>version recent Angabe, welche Version eines Objekts
    1> zur³ckgegeben werden muss
    1>win32_threads Nein Unterst³tzung von standardmõ▀igem lokalen
    1> Windows-Threading
    1>PCC-F-02135, CMD-LINE: Benutzer hat Hilfe angefordert
    1>Project : error PRJ0019: Ein Tool hat einen Fehlercode aus folgender Quelle zurückgegeben: "Oracle Precompiler"
    1>Das Buildprotokoll wurde unter "file://c:\Users\behli\Documents\Visual Studio 2008\Projects\ProcSample\ProcSample\Debug\BuildLog.htm" gespeichert.
    1>ProcSample - 1 Fehler, 0 Warnung(en)
    ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
    When i compile the file on the command line:
    proc.exe sample.pc
    it works correctly.
    Can anybody help me?
    Geetings
    Thomas

    Your question has everything to do with Microsoft and nothing to do with the topic of this forum which is "Database >> Installation."
    To get help either post in the correct .NET related forum or ask Microsoft how to make their tool work properly.

  • How to Convert the SQL to PL/SQL based on the Below SQL Example.

    I have an example which gives some example.
    If Actual Total Refund $ =
    But I got sum(Total Refund) = $199,999.50
    If i have total 100 rows which give the value 199,999.50 then first 50 rows i should receive an additional penny. to match the $200,000.00. and also vice versa.
    If Actual Total Refund $ = $199,999.50
    But I got sum(Total Refund) =$200,000.00
    then first 50 rows i should remove an additional penny. to match the 199,999.50 .
    I have written a quer to calculate the Sum( but not sure how to loop the amounts with adding pennies.
    SELECT LGL_ENT,JURDCN,FED_MKT_SEG,WRTN_PREM_PCTG,
    ROUND (REBT_AMT_PER_GRP,2), REBT_AMT_PER_GRP,ROUND(REBT_AMT_PER_GRP,2)- REBT_AMT_PER_GRP AS PEN_DIFF,
    SEG_CALCD_REBT, GRP_ID FROM
    SELECT PREM.LGL_ENT,PREM.JURDCN,EG.FED_MKT_SEG,SUM(PREM.WRTN_PREM_AMT) SUM_WRTN_AMT,
    (SUM(PREM.WRTN_PREM_AMT)/SPREM.WRTN_PREM_AMT) AS WRTN_PREM_PCTG,
    (SUM(PREM.WRTN_PREM_AMT)/SPREM.WRTN_PREM_AMT)*SEG.CALCD_REBT_AMT AS REBT_AMT_PER_GRP,
    SEG.CALCD_REBT_AMT AS SEG_CALCD_REBT, EG.GRP_ID
    FROM VTP.wrtn prem, wrtn_sum sprem,
    VTP.empr_size eg,
    VTP.seg seg
    WHERE
    PREM.LGL_ENT =SEG.LGL_ENT
    AND PREM.JURDCN= SEG.JURDCN
    AND EG.FED_MKT_SEG=SEG.FED_MKT_SEG
    AND PREM.LGL_ENT =SPREM.LGL_ENT
    AND PREM.JURDCN= SPREM.JURDCN
    AND EG.FED_MKT_SEG=SPREM.FED_MKT_SEG
    AND PREM.EMPR_GRP_SIZE_SKEY=EG.EMPR_GRP_SIZE_SKEY
    GROUP BY PREM.LGL_ENT, PREM.JURDCN, EG.FED_MKT_SEG, SEG.CALCD_REBT_AMT, EG.GRP_ID,SPREM.WRTN_PREM_AMT
    )ORDER BY REBT_AMT_PER_GRP ASC
    Thanks in advance for your support.

    Thanks for you Support For working with Me.
    Here is the sample Data for Actual Refund Amount is 800.00
    N GROUP     JURDCN      FED_MKT_SEG     ROUND(REBT_AMT_PER_GRP,2)     REBT_AMT_PER_GRP     Peeny Calculation      Actual Rebate That I should Match
    111 ….      MD …..      I M M ….      24.09     24.0936488     0.78          24.87
    112 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    113 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    114 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    115 ….      MD …..      I M M ….      40.57     40.5673183          0.78          41.35
    116 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    117 ….      MD …..      I M M ….      40.57     40.5673183          0.78          41.35
    118 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    119 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    120 ….      MD …..      I M M ….      16.06     16.06243253          0.78          16.84
    121 ….      MD …..      I M M ….      40.57     40.5673183          0.78          41.35
    122 ….      MD …..      I M M ….      9.2     9.198403569          0.78          9.98
    123 ….      MD …..      I M M ….      16.06     16.06243253          0.78          16.84
    124 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    125 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    126 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    127 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    128 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    129 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    130 ….      MD …..      I M M ….      40.57     40.5673183          0.78          41.35
    131 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    132 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    133 ….      MD …..      I M M ….      24.09     24.0936488          0.78          24.87
    134 ….      MD …..      I M M ….      40.57     40.5673183          0.78          41.35
    135 ….      MD …..      I M M ….      40.57     40.5673183          0.78          41.35
    136 ….      MD …..      I M M ….      24.09     24.0936488          0.77          24.86
    137 ….      MD …..      I M M ….      2.01     2.007804066          0.77          2.78
    138 ….      MD …..      I M M ….      40.57     40.5673183          0.77          41.34
    139 ….      MD …..      I M M ….      40.57     40.5673183          0.77          41.34
    Sum of Amount is                **777.42*     777.4616487          *800**
    I am Using 10G
    My Sql will only calculate the Amounts . But it will not work on Penny Calculations i should give loop logic for penny for each group untill it matches sum of Group Amuont

  • SQL examples and/or exercises for Oracle Express Edition

    Hi!
    I'm learning SQL with Oracle XE, i'm looking for examples or exercises to work with the XE example database for so i learn SQL.
    Somebody know something like this?
    Regards.

    start here
    http://www.oracle.com/technology/obe/start/index.html
    and read this
    http://www.oracle.com/pls/db102/homepage

  • Cannot run "Publish PL/SQL as a Web Service" example

    Hello!
    I have Oracle 8.1.7 AS and 9i JDeveloper running on Windows 2000. I'm trying to run the "Publish PL/SQL as a Web Service" example, but am encountering errors I believe are related to my hostname/IP address/DNS entry. Of course, I could be wrong.
    Here is some information:
    ==========================================================
    1. I was able to successfully initialize Containers for J2EE. However, when I was trying to deploy the PL/SQL example, it inserted this information:
    C:\oracle\jdev9i\j2ee\home>C:\oracle\jdev9i\jdk\bin\java.exe -jar C:\oracle\jdev9i\j2ee\home\oc4j.jar
    Node started with id=-1753996682
    Oracle9iAS (9.0.3.0.0) Containers for J2EE initialized
    Error updating application PLSQL-PLSQL-WS: Error loading web-app 'WebServices' at
    C:\oracle\jdev9i\j2ee\home\applications\PLSQL-PLSQL-WS\WebServices:
    resource-ref 'jdbc/testCoreDS' referenced from resource-ref-mapping not found
    ==========================================================
    2. I went through the instructions from the website, and when I began the deployment process it generated this information:
    ---- Deployment started. ---- Jan 17, 2003 1:20:27 PM
    Wrote WAR file to C:\oracle\jdev9i\jdev\plsql-webexample\Project1\WebSe[i]Long postings are being truncated to ~1 kB at this time.

    Couple of suggestions despite your post being cut off with what might be useful information (please post the rest if these suggestions don't help):
    1. There are some bugs with Personal Oracle and Web services, notably Oracle9i Personal that may apply also to 8.1.7. If you have a MetaLink account it is logged as bug 2591731.
    2. As you are using your local machine, make sure your proxies are turned off (Tools-Preferences Web Browser/Proxy)
    3. I've noticed problems when folks use a JDK with a version lower than 1.3.1_02 to run OC4J - it is certified only with 1.3.1_02 or higher. If you are using the built-in JDeveloper JDK to start up OC4J (e.g. <Jdev_home>\jdk\bin\java.exe) you should be fine. But if you are just typing in java -jar oc4j.jar it is worth checking. Check the your default JDK version by typing in: java -version. If it is lower, then download a new version from http://java.sun.com/j2se/1.3/download.html.
    4. For level setting it is best to be using build 1035 of JDeveloper, the current production release and either the OC4J embedded in it or the stand-alone version here on OTN.
    Hope these point in the right direction.
    Mike.

  • Example to access MS Excel by SQL tollkit

    I need example or document of accessing MS excel 2000
    by SQL toolkit for LabVIEW.
    My OS is win 98.
    T.U

    Hi Rony,
    Try these ...
    How Can I Use the SQL Toolkit in LabVIEW to Retrieve Data from a Microsoft Excel Spreadsheet?
    http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/862567530005f09c862566ac0076c303?OpenDocument
    SQL Example for Jet Databases (Excel and Access)
    http://zone.ni.com/devzone/explprog.nsf/6c163603265406328625682a006ed37d/005e3041f004ec5a86256568000a837b?OpenDocument
    SQL Demo zip.
    http://zone.ni.com/devzone/explprog.nsf/6c163603265406328625682a006ed37d/005e3041f004ec5a86256568000a837b/$FILE/SQLDemo.zip
    As far as I remember you can find some details in SQL Toolkit manual for G (if you don't have it, it's available for download from NI site).
    Good Luck ... and Happy Holidays!

  • Case statement in advanced sql

    how to use case statement in advanced sql.Example if quarter=1 i need to select jan,fev,and march months from table

    this is the case statement i am using :
    case when 1=@{quarter} then substring(cast((etxnmis.month_year) as char) from 5 for 2) IN ('03', '04', '05') else null end
    and i get the below error
    : HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <IN>: Syntax error [nQSError: 26012] . (HY000)

  • PL/SQL 101 : Exception Handling

    Frequently I see questions and issues around the use of Exception/Error Handling in PL/SQL.  More often than not the issue comes from the questioners misunderstanding about how PL/SQL is constructed and executed, so I thought I'd write a small article covering the key concepts to give a clear picture of how it all hangs together. (Note: the examples are just showing examples of the exception handling structure, and should not be taken as truly valid code for ways of handling things)
    Exception Handling
    Contents
    1. Understanding Execution Blocks (part 1)
    2. Execution of the Execution Block
    3. Exceptions
    4. Understanding Execution Blocks (part 2)
    5. How to continue exection of statements after an exception
    6. User defined exceptions
    7. Line number of exception
    8. Exceptions within code within the exception block
    1. Understanding Execution Blocks (part 1)
    The first thing that one needs to understand is almost taking us back to the basics of PL/SQL... how a PL/SQL execution block is constructed.
    Essentially an execution block is made of 3 sections...
    +---------------------------+
    |    Declaration Section    |
    +---------------------------+
    |    Statements  Section    |
    +---------------------------+
    |     Exception Section     |
    +---------------------------+
    The Declaration section is the part defined between the PROCEDURE/FUNCTION header or the DECLARE keyword (for anonymous blocks) and the BEGIN keyword.  (Optional section)
    The Statements section is where your code goes and lies between the BEGIN keyword and the EXCEPTION keyword (or END keyword if there is no EXCEPTION section).  (Mandatory section)
    The Exception section is where any exception handling goes and lies between the EXCEPTION keyword at the END keyword. (Optional section)
    Example of an anonymous block...
    DECLARE
      .. declarative statements go here ..
    BEGIN
      .. code statements go here ..
    EXCEPTION
      .. exception handlers go here ..
    END;
    Example of a procedure/function block...
    [CREATE OR REPLACE] (PROCEDURE|FUNCTION) <proc or fn name> [(<parameters>)] [RETURN <datatype>] (IS|AS)
      .. declarative statements go here ..
    BEGIN
      .. code statements go here ..
    EXCEPTION
      .. exception handlers go here ..
    END;
    (Note: The same can also be done for packages, but let's keep it simple)
    2. Execution of the Execution Block
    This may seem a simple concept, but it's surprising how many people have issues showing they haven't grasped it.  When an Execution block is entered, the declaration section is processed, creating a scope of variables, types , cursors, etc. to be visible to the execution block and then execution enters into the Statements section.  Each statment in the statements section is executed in turn and when the execution completes the last statment the execution block is exited back to whatever called it.
    3. Exceptions
    Exceptions generally happen during the execution of statements in the Statements section.  When an exception happens the execution of statements jumps immediately into the exception section.  In this section we can specify what exceptions we wish to 'capture' or 'trap' and do one of the two following things...
    (Note: The exception section still has access to all the declared items in the declaration section)
    3.i) Handle the exception
    We do this when we recognise what the exception is (most likely it's something we expect to happen) and we have a means of dealing with it so that our application can continue on.
    Example...
    (without the exception handler the exception is passed back to the calling code, in this case SQL*Plus)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3  begin
      4    select ename
      5    into   v_name
      6    from   emp
      7    where  empno = &empno;
      8    dbms_output.put_line(v_name);
      9* end;
    SQL> /
    Enter value for empno: 123
    old   7:   where  empno = &empno;
    new   7:   where  empno = 123;
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 4
    (with an exception handler, we capture the exception, handle it how we want to, and the calling code is happy that there is no error for it to report)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3  begin
      4    select ename
      5    into   v_name
      6    from   emp
      7    where  empno = &empno;
      8    dbms_output.put_line(v_name);
      9  exception
    10    when no_data_found then
    11      dbms_output.put_line('There is no employee with this employee number.');
    12* end;
    SQL> /
    Enter value for empno: 123
    old   7:   where  empno = &empno;
    new   7:   where  empno = 123;
    There is no employee with this employee number.
    PL/SQL procedure successfully completed.
    3.ii) Raise the exception
    We do this when:-
    a) we recognise the exception, handle it but still want to let the calling code know that it happened
    b) we recognise the exception, wish to log it happened and then let the calling code deal with it
    c) we don't recognise the exception and we want the calling code to deal with it
    Example of b)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3    v_empno NUMBER := &empno;
      4  begin
      5    select ename
      6    into   v_name
      7    from   emp
      8    where  empno = v_empno;
      9    dbms_output.put_line(v_name);
    10  EXCEPTION
    11    WHEN no_data_found THEN
    12      INSERT INTO sql_errors (txt)
    13      VALUES ('Search for '||v_empno||' failed.');
    14      COMMIT;
    15      RAISE;
    16* end;
    SQL> /
    Enter value for empno: 123
    old   3:   v_empno NUMBER := &empno;
    new   3:   v_empno NUMBER := 123;
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 15
    SQL> select * from sql_errors;
    TXT
    Search for 123 failed.
    SQL>
    Example of c)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3    v_empno NUMBER := &empno;
      4  begin
      5    select ename
      6    into   v_name
      7    from   emp
      8    where  empno = v_empno;
      9    dbms_output.put_line(v_name);
    10  EXCEPTION
    11    WHEN no_data_found THEN
    12      INSERT INTO sql_errors (txt)
    13      VALUES ('Search for '||v_empno||' failed.');
    14      COMMIT;
    15      RAISE;
    16    WHEN others THEN
    17      RAISE;
    18* end;
    SQL> /
    Enter value for empno: 'ABC'
    old   3:   v_empno NUMBER := &empno;
    new   3:   v_empno NUMBER := 'ABC';
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 3
    SQL> select * from sql_errors;
    TXT
    Search for 123 failed.
    SQL>
    As you can see from the sql_errors log table, no log was written so the WHEN others exception was the exception that raised the error to the calling code (SQL*Plus)
    4. Understanding Execution Blocks (part 2)
    Ok, so now we understand the very basics of an execution block and what happens when an exception happens.  Let's take it a step further...
    Execution blocks are not just a single simple block in most cases.  Often, during our statements section we have a need to call some reusable code and we do that by calling a procedure or function.  Effectively this nests the procedure or function's code as another execution block within the current statement section so, in terms of execution, we end up with something like...
    +---------------------------------+
    |    Declaration Section          |
    +---------------------------------+
    |    Statements  Section          |
    |            .                    |
    |  +---------------------------+  |
    |  |    Declaration Section    |  |
    |  +---------------------------+  |
    |  |    Statements  Section    |  |
    |  +---------------------------+  |
    |  |     Exception Section     |  |
    |  +---------------------------+  |
    |            .                    |
    +---------------------------------+
    |     Exception Section           |
    +---------------------------------+
    Example... (Note: log_trace just writes some text to a table for tracing)
    SQL> create or replace procedure a as
      2    v_dummy NUMBER := log_trace('Procedure A''s Declaration Section');
      3  begin
      4    v_dummy := log_trace('Procedure A''s Statement Section');
      5    v_dummy := 1/0; -- cause an exception
      6  exception
      7    when others then
      8      v_dummy := log_trace('Procedure A''s Exception Section');
      9      raise;
    10  end;
    11  /
    Procedure created.
    SQL> create or replace procedure b as
      2    v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
      3  begin
      4    v_dummy := log_trace('Procedure B''s Statement Section');
      5    a; -- HERE the execution passes to the declare/statement/exception sections of A
      6  exception
      7    when others then
      8      v_dummy := log_trace('Procedure B''s Exception Section');
      9      raise;
    10  end;
    11  /
    Procedure created.
    SQL> exec b;
    BEGIN b; END;
    ERROR at line 1:
    ORA-01476: divisor is equal to zero
    ORA-06512: at "SCOTT.B", line 9
    ORA-06512: at line 1
    SQL> select * from code_trace;
    TXT
    Procedure B's Declaration Section
    Procedure B's Statement Section
    Procedure A's Declaration Section
    Procedure A's Statement Section
    Procedure A's Exception Section
    Procedure B's Exception Section
    6 rows selected.
    SQL>
    Likewise, execution blocks can be nested deeper and deeper.
    5. How to continue exection of statements after an exception
    One of the common questions asked is how to return execution to the statement after the one that created the exception and continue on.
    Well, firstly, you can only do this for statements you expect to raise an exception, such as when you want to check if there is no data found in a query.
    If you consider what's been shown above you could put any statement you expect to cause an exception inside it's own procedure or function with it's own exception section to handle the exception without raising it back to the calling code.  However, the nature of procedures and functions is really to provide a means of re-using code, so if it's a statement you only use once it seems a little silly to go creating individual procedures for these.
    Instead, you nest execution blocks directly, to give the same result as shown in the diagram at the start of part 4 of this article.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure b (p_empno IN VARCHAR2) as
      2    v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
      3  begin
      4    v_dummy := log_trace('Procedure B''s Statement Section');
      5    -- Here we start another execution block nested in the first one...
      6    declare
      7      v_dummy NUMBER := log_trace('Nested Block Declaration Section');
      8    begin
      9      v_dummy := log_trace('Nested Block Statement Section');
    10      select empno
    11        into   v_dummy
    12        from   emp
    13       where  empno = p_empno; -- Note: the parameters and variables from
                                         parent execution block are available to use!
    14    exception
    15      when no_data_found then
    16        -- This is an exception we can handle so we don't raise it
    17        v_dummy := log_trace('No employee was found');
    18        v_dummy := log_trace('Nested Block Exception Section - Exception Handled');
    19      when others then
    20        -- Other exceptions we can't handle so we raise them
    21        v_dummy := log_trace('Nested Block Exception Section - Exception Raised');
    22        raise;
    23    end;
    24    -- ...Here endeth the nested execution block
    25    -- As the nested block handled it's exception we come back to here...
    26    v_dummy := log_trace('Procedure B''s Statement Section Continued');
    27  exception
    28    when others then
    29      -- We'll only get to here if an unhandled exception was raised
    30      -- either in the nested block or in procedure b's statement section
    31      v_dummy := log_trace('Procedure B''s Exception Section');
    32      raise;
    33* end;
    SQL> /
    Procedure created.
    SQL> exec b(123);
    PL/SQL procedure successfully completed.
    SQL> select * from code_trace;
    TXT
    Procedure B's Declaration Section
    Procedure B's Statement Section
    Nested Block Declaration Section
    Nested Block Statement Section
    No employee was found
    Nested Block Exception Section - Exception Handled
    Procedure B's Statement Section Continued
    7 rows selected.
    SQL> truncate table code_trace;
    Table truncated.
    SQL> exec b('ABC');
    BEGIN b('ABC'); END;
    ERROR at line 1:
    ORA-01722: invalid number
    ORA-06512: at "SCOTT.B", line 32
    ORA-06512: at line 1
    SQL> select * from code_trace;
    TXT
    Procedure B's Declaration Section
    Procedure B's Statement Section
    Nested Block Declaration Section
    Nested Block Statement Section
    Nested Block Exception Section - Exception Raised
    Procedure B's Exception Section
    6 rows selected.
    SQL>
    You can see from this that, very simply, the code that we expected may have an exception was able to either handle the exception and return to the outer execution block to continue execution, or if an unexpected exception occurred then it was able to be raised up to the outer exception section.
    6. User defined exceptions
    There are three sorts of 'User Defined' exceptions.  There are logical situations (e.g. business logic) where, for example, certain criteria are not met to complete a task, and there are existing Oracle errors that you wish to give a name to in order to capture them in the exception section.  The third is raising your own exception messages with our own exception numbers.  Let's look at the first one...
    Let's say I have tables which detail stock availablility and reorder levels...
    SQL> select * from reorder_level;
       ITEM_ID STOCK_LEVEL
             1          20
             2          20
             3          10
             4           2
             5           2
    SQL> select * from stock;
       ITEM_ID ITEM_DESC  STOCK_LEVEL
             1 Pencils             10
             2 Pens                 2
             3 Notepads            25
             4 Stapler              5
             5 Hole Punch           3
    SQL>
    Now, our Business has told the administrative clerk to check stock levels and re-order anything that is below the re-order level, but not to hold stock of more than 4 times the re-order level for any particular item.  As an IT department we've been asked to put together an application that will automatically produce the re-order documents upon the clerks request and, because our company is so tight-ar*ed about money, they don't want to waste any paper with incorrect printouts so we have to ensure the clerk can't order things they shouldn't.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6      from stock s join reorder_level r on (s.item_id = r.item_id)
      7      where s.item_id = p_item_id;
      8    --
      9    v_stock cur_stock_reorder%ROWTYPE;
    10  begin
    11    OPEN cur_stock_reorder;
    12    FETCH cur_stock_reorder INTO v_stock;
    13    IF cur_stock_reorder%NOTFOUND THEN
    14      RAISE no_data_found;
    15    END IF;
    16    CLOSE cur_stock_reorder;
    17    --
    18    IF v_stock.stock_level >= v_stock.reorder_level THEN
    19      -- Stock is not low enough to warrant an order
    20      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    21    ELSE
    22      IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    23        -- Required amount is over-ordering
    24        DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                     ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    25      ELSE
    26        DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    27        -- Here goes our code to print the order
    28      END IF;
    29    END IF;
    30    --
    31  exception
    32    WHEN no_data_found THEN
    33      CLOSE cur_stock_reorder;
    34      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    35* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(10,100);
    Invalid Item ID.
    PL/SQL procedure successfully completed.
    SQL> exec re_order(3,40);
    Stock has not reached re-order level yet!
    PL/SQL procedure successfully completed.
    SQL> exec re_order(1,100);
    Quantity specified is too much.  Max for this item: 70
    PL/SQL procedure successfully completed.
    SQL> exec re_order(2,50);
    Order OK.  Printing Order...
    PL/SQL procedure successfully completed.
    SQL>
    Ok, so that code works, but it's a bit messy with all those nested IF statements. Is there a cleaner way perhaps?  Wouldn't it be nice if we could set up our own exceptions...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6      from stock s join reorder_level r on (s.item_id = r.item_id)
      7      where s.item_id = p_item_id;
      8    --
      9    v_stock cur_stock_reorder%ROWTYPE;
    10    --
    11    -- Let's declare our own exceptions for business logic...
    12    exc_not_warranted EXCEPTION;
    13    exc_too_much      EXCEPTION;
    14  begin
    15    OPEN cur_stock_reorder;
    16    FETCH cur_stock_reorder INTO v_stock;
    17    IF cur_stock_reorder%NOTFOUND THEN
    18      RAISE no_data_found;
    19    END IF;
    20    CLOSE cur_stock_reorder;
    21    --
    22    IF v_stock.stock_level >= v_stock.reorder_level THEN
    23      -- Stock is not low enough to warrant an order
    24      RAISE exc_not_warranted;
    25    END IF;
    26    --
    27    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    28      -- Required amount is over-ordering
    29      RAISE exc_too_much;
    30    END IF;
    31    --
    32    DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    33    -- Here goes our code to print the order
    34    --
    35  exception
    36    WHEN no_data_found THEN
    37      CLOSE cur_stock_reorder;
    38      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    39    WHEN exc_not_warranted THEN
    40      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    41    WHEN exc_too_much THEN
    42      DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                  ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    43* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(10,100);
    Invalid Item ID.
    PL/SQL procedure successfully completed.
    SQL> exec re_order(3,40);
    Stock has not reached re-order level yet!
    PL/SQL procedure successfully completed.
    SQL> exec re_order(1,100);
    Quantity specified is too much.  Max for this item: 70
    PL/SQL procedure successfully completed.
    SQL> exec re_order(2,50);
    Order OK.  Printing Order...
    PL/SQL procedure successfully completed.
    SQL>
    That's better.  And now we don't have to use all those nested IF statements and worry about it accidently getting to code that will print the order out as, once one of our user defined exceptions is raised, execution goes from the Statements section into the Exception section and all handling of errors is done in one place.
    Now for the second sort of user defined exception...
    A new requirement has come in from the Finance department who want to have details shown on the order that show a re-order 'indicator' based on the formula ((maximum allowed stock - current stock)/re-order quantity), so this needs calculating and passing to the report...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6            ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
      7      from stock s join reorder_level r on (s.item_id = r.item_id)
      8      where s.item_id = p_item_id;
      9    --
    10    v_stock cur_stock_reorder%ROWTYPE;
    11    --
    12    -- Let's declare our own exceptions for business logic...
    13    exc_not_warranted EXCEPTION;
    14    exc_too_much      EXCEPTION;
    15  begin
    16    OPEN cur_stock_reorder;
    17    FETCH cur_stock_reorder INTO v_stock;
    18    IF cur_stock_reorder%NOTFOUND THEN
    19      RAISE no_data_found;
    20    END IF;
    21    CLOSE cur_stock_reorder;
    22    --
    23    IF v_stock.stock_level >= v_stock.reorder_level THEN
    24      -- Stock is not low enough to warrant an order
    25      RAISE exc_not_warranted;
    26    END IF;
    27    --
    28    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    29      -- Required amount is over-ordering
    30      RAISE exc_too_much;
    31    END IF;
    32    --
    33    DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    34    -- Here goes our code to print the order, passing the finance_factor
    35    --
    36  exception
    37    WHEN no_data_found THEN
    38      CLOSE cur_stock_reorder;
    39      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    40    WHEN exc_not_warranted THEN
    41      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    42    WHEN exc_too_much THEN
    43      DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                  ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    44* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(2,40);
    Order OK.  Printing Order...
    PL/SQL procedure successfully completed.
    SQL> exec re_order(2,0);
    BEGIN re_order(2,0); END;
    ERROR at line 1:
    ORA-01476: divisor is equal to zero
    ORA-06512: at "SCOTT.RE_ORDER", line 17
    ORA-06512: at line 1
    SQL>
    Hmm, there's a problem if the person specifies a re-order quantity of zero.  It raises an unhandled exception.
    Well, we could put a condition/check into our code to make sure the parameter is not zero, but again we would be wrapping our code in an IF statement and not dealing with the exception in the exception handler.
    We could do as we did before and just include a simple IF statement to check the value and raise our own user defined exception but, in this instance the error is standard Oracle error (ORA-01476) so we should be able to capture it inside the exception handler anyway... however...
    EXCEPTION
      WHEN ORA-01476 THEN
    ... is not valid.  What we need is to give this Oracle error a name.
    This is done by declaring a user defined exception as we did before and then associating that name with the error number using the PRAGMA EXCEPTION_INIT statement in the declaration section.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6            ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
      7      from stock s join reorder_level r on (s.item_id = r.item_id)
      8      where s.item_id = p_item_id;
      9    --
    10    v_stock cur_stock_reorder%ROWTYPE;
    11    --
    12    -- Let's declare our own exceptions for business logic...
    13    exc_not_warranted EXCEPTION;
    14    exc_too_much      EXCEPTION;
    15    --
    16    exc_zero_quantity EXCEPTION;
    17    PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
    18  begin
    19    OPEN cur_stock_reorder;
    20    FETCH cur_stock_reorder INTO v_stock;
    21    IF cur_stock_reorder%NOTFOUND THEN
    22      RAISE no_data_found;
    23    END IF;
    24    CLOSE cur_stock_reorder;
    25    --
    26    IF v_stock.stock_level >= v_stock.reorder_level THEN
    27      -- Stock is not low enough to warrant an order
    28      RAISE exc_not_warranted;
    29    END IF;
    30    --
    31    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    32      -- Required amount is over-ordering
    33      RAISE exc_too_much;
    34    END IF;
    35    --
    36    DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    37    -- Here goes our code to print the order, passing the finance_factor
    38    --
    39  exception
    40    WHEN exc_zero_quantity THEN
    41      DBMS_OUTPUT.PUT_LINE('Quantity of 0 (zero) is invalid.');
    42    WHEN no_data_found THEN
    43      CLOSE cur_stock_reorder;
    44      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    45    WHEN exc_not_warranted THEN
    46      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    47    WHEN exc_too_much THEN
    48      DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                  ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    49* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(2,0);
    Quantity of 0 (zero) is invalid.
    PL/SQL procedure successfully completed.
    SQL>
    Lastly, let's look at raising our own exceptions with our own exception numbers...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6            ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
      7      from stock s join reorder_level r on (s.item_id = r.item_id)
      8      where s.item_id = p_item_id;
      9    --
    10    v_stock cur_stock_reorder%ROWTYPE;
    11    --
    12    exc_zero_quantity EXCEPTION;
    13    PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
    14  begin
    15    OPEN cur_stock_reorder;
    16    FETCH cur_stock_reorder INTO v_stock;
    17    IF cur_stock_reorder%NOTFOUND THEN
    18      RAISE no_data_found;
    19    END IF;
    20    CLOSE cur_stock_reorder;
    21    --
    22    IF v_stock.stock_level >= v_stock.reorder_level THEN
    23      -- Stock is not low enough to warrant an order
    24      [b]RAISE_APPLICATION_ERROR(-20000, 'Stock has not reached re-order level yet!');[/b]
    25    END IF;
    26    --
    27    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    28      -- Required amount is over-ordering
    29     

    its nice article, have put up this one the blog
    site,Nah, I don't have time to blog, but if one of the other Ace's/Experts wants to copy it to a blog with reference back to here (and all due credit given ;)) then that's fine by me.
    I'd go for a book like "Selected articles by OTN members" or something. Does anybody have a list of links of all those mentioned articles?Just these ones I've bookmarked...
    Introduction to regular expressions ... by CD
    When your query takes too long ... by Rob van Wijk
    How to pipeline a function with a dynamic number of columns? by ascheffer
    PL/SQL 101 : Exception Handling by BluShadow

Maybe you are looking for

  • Aperture No Longer Working With Screen Saver?

    For years I've been using my Aperture library (specifically, the "Flagged Photos") with the Screen Saver in OS X.  Since I upgraded to Lion last night, I have discovered that my Aperture library no longer shows up as an option in Screen Saver -- only

  • Installing Windows XP on Macbook Pro 17 inch with broken screen...

    My Macbook Pro 17 inch's (2.16 ghz, 2006) screen is broken, and displays only the top 1/4 accurately, with the lower 3/4 a series of lines, etc... Up until recently, the screen would work after a period of time so long as I did not move it. However,

  • Scan to email server connection error for HP Envy 5530

    Hi, Everyone! I LOVE my printer.  But, I had to add another laptop (both WIndows) - and then had to add a couple of monitors to that laptop (and a docking statiion) and now it doesn't want to scan to my emails any longer after working like gangbuster

  • How can I fix "Reading Global Text Resources" error with my Photoshop CS?

    I've sought help and info online. coming to the same explanations, the only catch? I cannot Find on my machine the very suggestions they make. I have a Dell Inspiron 6200. Windows 7. I have Adobe Photoshop CS, and suddenly, not long ago, it stopped.

  • Vista SP1 -- Driver issues with T61

    Vista SP1 is now avaibale through automatic downloads. However, it is not available for my T61. A quick search on the net reveals that there appear to be some issues with the drivers -- finger print and Intel integrated video drivers. Are there any w