Help....on stored procedure (or package)

Hi,
I have any problem to create stored procedure in Oracle, Can you help me?
I have to create a stored procedure (or package) in order to reserve the free rooms to the students in the period comprised between the DATE_START and DATE_END.
Table of the present rooms in building BL1 (RM): SEX 1 = M - SEX 2 = F SEX = 0 (ROOM WITHOUT SEX)
BL_ID.....FL_ID.......RM_ID.........SEX......RM_STD.....RM_CAT
BL1.........1..........101..............1........S........ROOM
BL1.........1..........102..............0........D........ROOM
BL1.........1..........103..............2........T........ROOM
BL1.........2..........201..............2........S........ROOM
BL1.........2..........202..............1........D........ROOM
BL1.........2..........203..............1........T........ROOM
BL1.........3..........301..............2........S........APARTMENT
BL1.........3..........302..............2........D........APARTMENT
BL1.........3..........303..............1........T........APARTMENT
BL1.........3..........304..............1........D........APARTMENT
BL1.........3..........305..............0........D........APARTMENT
Table of the students (EM):
EM_ID...........BL_ID.......FL_ID........RM_ID........COD_STUD
SABRINA..........BL1..........1............102.........524505
TAKEM............BL1..........1............103.........569673
SERAFINO.........BL1..........1............103.........589920
STELLA...........BL1..........1............102.........574659
CHIARA...........BL1..........1............101.........587845
VIDAL............BL1..........1............102.........602877
ROSARIA..........BL1..........2............202.........517070
LUCA.............BL1..........2............201.........602743
DANIELA..........BL1..........2............203.........602865
ANNAMARIA........BL1..........3............305.........588721
LUIGI............BL1..........3............304.........546517
Type of rooms (RM_STD):
RM_STD.......STD_EM........DESCRIPTION
D.............4..............DOUBLE
T.............6..............TRIPLE
S.............2..............SINGLE
Tables of the reservations carried out from the students (RMPCT):
EM_ID......BL_ID........FL_ID......RM_ID......DATE_START.......DATE_END.......COD_STUD
CHIARA......BL1.........1..........101.......11/02/2004.......12/02/2004.......587845
CHIARA......BL1.........1..........101.......03/02/2005.......16/02/2005.......587845
SERAFINO....BL1.........1..........102.......12/02/2004.......19/02/2004.......589920
VIDAL.......BL1.........1..........102.......16/02/2004.......01/03/2004.......602877
SERAFINO....BL1.........1..........103.......01/02/2004.......15/02/2004.......589920
TAKEM.......BL1.........1..........103.......04/02/2005.......10/02/2005.......569673
LUCA........BL1.........2..........201.......03/02/2005.......23/02/2005.......602743
ROSARIA.....BL1.........2..........202.......03/02/2005.......16/02/2005.......517070
DANIELA.....BL1.........2..........203.......03/02/2005.......04/02/2005.......602865
LUIGI.......BL1.........3..........301.......03/02/2005.......23/02/2005.......546517
VALERIA.....BL1.........3..........302.......12/02/2004.......16/02/2004.......515348
CHIARA......BL1.........3..........302.......05/02/2004.......15/02/2004.......587845
CHIARA......BL1.........3..........304.......10/02/2004.......12/02/2004.......587845
CHIARA......BL1.........3..........305.......20/01/2004.......04/02/2004.......587845
ANNAMARIA...BL1.........3..........305.......03/02/2005.......16/02/2005.......588721
INPUT PARAMETERS:
CREATE OR REPLACE Procedure RESERVE_ROOMS (stud_name varchar2,
cod_stud varchar2,
bl_in varchar2,
fl_in varchar2,
rm_in in varchar2,
sex_in varchar2,
date_start_in varchar2,
date_end_in varchar2)
CONDITIONS:
verify if there are students in table EM:
select count (1)
into v_appo
from em
where em_id = stud_name
and cod_stud = cod_stud;
if v_appo = 0 then
insert new student:
          insert into em (em_id,cod_sud,sex)
values (stud_name,cod_stud,sex_in);
Now I must verify the free rooms in the period comprised between the DATE_START_IN and DATE_END_IN.
I tried this query: (seem correct...have you any idea?)
select bl_id,fl_id,rm_id,RM_STD
from rm
where (bl_id,fl_id,rm_id,RM_STD) not in (select a.bl_id,a.fl_id,a.rm_id,A.RM_STD
                         from rm a, rmpct b
                         where a.bl_id=b.bl_id
                         and a.fl_id=b.fl_id
                         and a.rm_id=b.rm_id
                         AND((b.date_start <= TO_DATE(date_start_in, 'dd-mm-YYYY')
                         AND b.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))
                         OR ( b.date_end <= TO_DATE(date_end_in, 'dd-mm-YYYY'))
                         AND b.date_end >= TO_DATE(date_start_in, 'dd-mm-YYYY')
                         OR ( b.date_start >= TO_DATE(date_start_in, 'dd-mm-YYYY')
                         and b.date_start <= TO_DATE(date_end_in, 'dd-mm-YYYY')
                         AND b.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))))
with this query I get all free rooms in period date_start_in - date_end_in, but I must,also,verify if there are double or triple rooms (reserved) with minus of 2 (double) or minus of 3 (triple) students. If there are I can reserved these rooms.
I tried to verify with these steps:
CREATE OR REPLACE VIEW COUNT_EM ( BL_ID,
FL_ID, RM_ID, NUMBER_EM ) AS
(SELECT rm.bl_id, rm.fl_id, rm.rm_id, COUNT(*) as numero_em
FROM em, rm
WHERE em.bl_id(+) = rm.bl_id
AND em.fl_id(+) = rm.fl_id
AND em.rm_id(+) = rm.rm_id
and rm.rm_std in ('S', 'D', 'T')
group by rm.bl_id, rm.fl_id, rm.rm_id)
CREATE OR REPLACE VIEW COUNT_RMPCT ( BL_ID,
FL_ID, RM_ID, STD_EM, NUMBER_RMPCT
) AS
SELECT rm.bl_id, rm.fl_id, rm.rm_id, rmstd.std_em, COUNT(*) as numero_rmpct
FROM rm, rmpct,rmstd
WHERE rmpct.bl_id(+) = rm.bl_id
AND rmpct.fl_id(+) = rm.fl_id
AND rmpct.rm_id(+) = rm.rm_id
and rm.rm_std=rmstd.rm_std
and rm.rm_std in ('S', 'D', 'T')
AND((rmpct.date_start <= TO_DATE(date_start_in', 'dd-mm-YYYY')
AND rmpct.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))
OR ( rmpct.date_end <= TO_DATE(date_end_in, 'dd-mm-YYYY'))
AND rmpct.date_end >= TO_DATE(date_start_in, 'dd-mm-YYYY')
OR ( rmpct.date_start >= TO_DATE(date_start_in, 'dd-mm-YYYY')
and rmpct.date_start <= TO_DATE(date_end_in, 'dd-mm-YYYY')
AND rmpct.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY')))
group by rm.bl_id, rm.fl_id, rm.rm_id, rmstd.std_em
AND FINALLY:
select a.bl_id, a.fl_id, a.rm_id, a.NUMBER_RMPCT, B.NUMBER_EM, a.std_em, (a.std_em - (a.NUMBER_RMPCT+B.NUMBER_EM)) RM_FREE
from COUNT_RMPCT a, COUNT_EM b
where a.bl_id=b.bl_id
and a.fl_id=b.fl_id
and a.rm_id=b.rm_id
if RM_FREE > 0 THEN there are free rooms (D or T) between those occupied in that period.
Now If the room (bl_in,fl_in,rm_in) is free I can reserve inserting it in the table RMPCT:
INSERT INTO rmpct (bl_id, fl_id, rm_id,em_id,cod_stud,date_start, date_end)
values(bl_in,fl_in,rm_in,stud_name,cod_stud,date_start_in,date_end_in);
If I haven't rm_in (can be null) I must reserve the first free room (random).
after these controls: I update table of the students:
UPDATE em
Set bl_id = BL_IN,fl_id= FL_IN,rm_id=rm_in
     where em_id=stud_name
     and cod_stud=cod_stud;
Finally I must make a control on the sex of the room, because there are rooms that have sex=0
if RM.SEX <> 0 then
     null
else
if rm_cat = 'ROOM' then
UPDATE rm
set sex = sex_in
where bl_id = in
and fl_id = in
and rm_id = in;
if rm_cat = 'APARTMENT' then (update on all rooms)
UPDATE rm
set sex = sex_in
where bl_id = in
and fl_id = in;
IF v_appo > 0 then
     Same controls except:      insert into em (em_id,cod_sud,sex)
               values (stud_name,cod_stud,sex_in);
How I can insert in one stored procedure (or package) all these instructions and controls?
Thanks in advance!

In the following demonstation, I have changed the names of some of your variables, in order to standardize them. I have prefaced input parameters with p_ and local variables with v_ and followed them with the name of the column that they are associated with when appropriate. This avoids conflicts with any column names and makes the code easier to read and follow. I have also used table_name.column_name%type to specify the data type associated with the variables instead of using varchar2. That way, if the data type of the columns changes, the code does not have to be updated. This is standard practice.
In your first insert statement, you have attempted to insert sex into the em table, but there is no sex column in the em table data that you displayed, so I removed the sex.
Instead of using a complicated mess of views and such to check whether there is a room available and then assign it, I have used just one select statement to select an available room and used an exception clause that handles a no_data_found exception to deal with when there is no room available.
I have greatly simplified your checking of dates within that select statement.
You were on the right track with the outer joins and grouping and checking for single, double, or triple rooms. Instead of count, I have used sum and nvl2, so that only the occupied rooms are counted and the rows generated by the outer join are zeroes.
I have used the nvl function to allow for null values in the input parameters, so that any room can be selected. I used dbms_random.random to ensure that the rows are ordered randomly, but you can leave that out if it is really not that critical that the result be truly random and any row will do. I have used rownum=1 in an outer query to select just one row.
When you select from a table in pl/sql, you have to select into something. You cannot just issue a select statement, then use an if statement to compare some value in the select statement. For example, you cannot use "if rm.sex ..." you have to select rm.sex into a variable, like v_sex, then use "if v_sex ...". So, I have selected the result of the select statement into local variables, then used those variables for comparisons. I have also used those variables for inserting and updating the appropriate tables, rather than just using the original input parameters, since some of them may have been null.
In the example below, I have demonstrated how the procedure rejects an unavailable room, accepts a specific available room, and randomly assigns a room.
-- procedure:
scott@ORA92> CREATE OR REPLACE PROCEDURE reserve_rooms
  2    -- input parameters:
  3    (p_em_id      IN em.em_id%TYPE,
  4       p_cod_stud   IN em.cod_stud%TYPE,
  5       p_bl_id      IN rm.bl_id%TYPE,
  6       p_fl_id      IN rm.fl_id%TYPE,
  7       p_rm_id      IN rm.rm_id%TYPE,
  8       p_sex          IN rm.sex%TYPE,
  9       p_date_start IN VARCHAR2,
10       p_date_end   IN VARCHAR2)
11  AS
12    -- local variables:
13    v_appo          INTEGER;
14    v_bl_id          rm.bl_id%TYPE;
15    v_fl_id          rm.fl_id%TYPE;
16    v_rm_id          rm.rm_id%TYPE;
17    v_rm_cat      rm.rm_cat%TYPE;
18    v_sex          rm.sex%TYPE;
19  BEGIN
20    -- verify if the student is in table em:
21    SELECT COUNT (*)
22    INTO   v_appo
23    FROM   em
24    WHERE  em_id = p_em_id
25    AND    cod_stud = p_cod_stud;
26    -- if the student is not in table em, then insert new student:
27    IF v_appo = 0 THEN
28        INSERT INTO em (em_id, cod_stud)
29        VALUES (p_em_id, p_cod_stud);
30    END IF;
31    BEGIN
32        -- find available room:
33        SELECT bl_id, fl_id, rm_id, sex, rm_cat
34        INTO     v_bl_id, v_fl_id, v_rm_id, v_sex, v_rm_cat
35        FROM     (SELECT rm.bl_id, rm.fl_id, rm.rm_id, rm.sex, rm.rm_cat
36             FROM     rmpct, rm
37             WHERE     rm.bl_id = rmpct.bl_id (+)
38             AND     rm.fl_id = rmpct.fl_id (+)
39             AND     rm.rm_id = rmpct.rm_id (+)
40             AND     rm.bl_id = NVL (p_bl_id, rm.bl_id)
41             AND     rm.fl_id = NVL (p_fl_id, rm.fl_id)
42             AND     rm.rm_id = NVL (p_rm_id, rm.rm_id)
43             AND     (rm.sex   = p_sex OR rm.sex = 0)
44             AND     rmpct.date_start (+) <= TO_DATE (p_date_end, 'DD-MM-YYYY')
45             AND     rmpct.date_end (+) >= TO_DATE (p_date_start, 'DD-MM-YYYY')
46             GROUP     BY rm.bl_id, rm.fl_id, rm.rm_id, rm.sex, rm.rm_cat, rm.rm_std
47             HAVING SUM (NVL2 (rmpct.rm_id (+), 1, 0))
48                 < DECODE (rm_std, 'S', 1, 'D', 2, 'T', 3)
49             ORDER     BY DBMS_RANDOM.RANDOM)
50        WHERE ROWNUM = 1;
51        -- reserve room:
52        INSERT INTO rmpct (bl_id, fl_id, rm_id, em_id, cod_stud, date_start, date_end)
53        VALUES (v_bl_id, v_fl_id, v_rm_id, p_em_id, p_cod_stud,
54             TO_DATE (p_date_start, 'DD-MM-YYYY'),
55             TO_DATE (p_date_end, 'DD-MM-YYYY'));
56        -- update students:
57        UPDATE em
58        SET     bl_id = v_bl_id, fl_id = v_fl_id, rm_id = v_rm_id
59        WHERE     em_id = p_em_id
60        AND     cod_stud = p_cod_stud;
61        -- update sex of room or apartment floor:
62        IF v_sex = 0 THEN
63          IF v_rm_cat = 'ROOM' THEN
64            UPDATE rm
65            SET    sex = p_sex
66            WHERE  bl_id = v_bl_id
67            AND    fl_id = v_fl_id
68            AND    rm_id = v_rm_id;
69          ELSIF v_rm_cat = 'APARTMENT' THEN
70            UPDATE rm
71            SET    sex = p_sex
72            WHERE  bl_id = v_bl_id
73            AND    fl_id = v_fl_id;
74          END IF;
75        END IF;
76    EXCEPTION
77        -- if no room is available:
78        WHEN NO_DATA_FOUND THEN
79          RAISE_APPLICATION_ERROR (-20001, 'Sorry, there is no such room available.');
80    END;
81  END reserve_rooms;
82  /
Procedure created.
scott@ORA92> SHOW ERRORS
No errors.
-- rejects unavailable room of wrong sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, 'BL1', 1, 101, 2, '04-02-2005', '10-02-2005')
BEGIN reserve_rooms ('BARBARA', 654321, 'BL1', 1, 101, 2, '04-02-2005', '10-02-2005'); END;
ERROR at line 1:
ORA-20001: Sorry, there is no such room available.
ORA-06512: at "SCOTT.RESERVE_ROOMS", line 79
ORA-06512: at line 1
-- accepts available room of same sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, 'BL1', 1, 103, 2, '04-02-2005', '10-02-2005')
PL/SQL procedure successfully completed.
-- assigns random available room of same or no sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, NULL, NULL, NULL, 2, '11-02-2005', '23-02-2005')
PL/SQL procedure successfully completed.
-- results:
scott@ORA92> -- one and only one row added to em table:
scott@ORA92> SELECT * FROM em WHERE em_id = 'BARBARA'
  2  /
EM_ID           BL_I      FL_ID      RM_ID   COD_STUD
BARBARA         BL1           1        102     654321
scott@ORA92> -- rooms reserved and other people who have reserved same room
scott@ORA92> -- (there are 3 who reserved a double room, but only 2 at a time):
scott@ORA92> SELECT *
  2  FROM   rmpct
  3  WHERE  (bl_id, fl_id, rm_id) IN
  4           (SELECT bl_id, fl_id, rm_id
  5            FROM   rmpct
  6            where  em_id = 'BARBARA')
  7  /
EM_ID           BL_      FL_ID      RM_ID DATE_STAR DATE_END    COD_STUD
BARBARA         BL1          1        102 11-FEB-05 23-FEB-05     654321
SERAFINO        BL1          1        102 12-FEB-04 19-FEB-04     589920
VIDAL           BL1          1        102 16-FEB-04 01-MAR-04     602877
SERAFINO        BL1          1        103 01-FEB-04 15-FEB-04     589920
TAKEM           BL1          1        103 04-FEB-05 10-FEB-05     569673
BARBARA         BL1          1        103 04-FEB-05 10-FEB-05     654321
6 rows selected.
scott@ORA92> -- rooms reserved are all correct sex
scott@ORA92> -- (note that room 102 was updated from 0 to 2):
scott@ORA92> SELECT *
  2  FROM   rm
  3  WHERE  (bl_id, fl_id, rm_id) IN
  4           (SELECT bl_id, fl_id, rm_id
  5            FROM   rmpct
  6            where  em_id = 'BARBARA')
  7  /
BL_      FL_ID      RM_ID        SEX R RM_CAT
BL1          1        102          2 D ROOM
BL1          1        103          2 T ROOM
scott@ORA92>

Similar Messages

  • Oracle stored Procedure and Packages in CR4E

    Hi,
    I want to use Stored Procedure in CR4E. I don't know how to use Stored Procedures and packages in Crystal Reports for Eclipse. In the data source explorer I can only see the Tables, Views and Stored Procedures but not packages from my Schema and when I can only drag & drop the Tables and Views into the Field Explorer, I can't drag & Drop the Stored Procedures.
    I managed to attached the stored procedure from CR studio. I opened the report in CR4E and I can see the stored procedure and can preview the data. When I try to run the report and override the datasource, it throws oracle error saying "ORA-01008: Not all variables bound". When I tried to use the option
    DBOptions._doNotVerifyDB
    while replacing connection I get the this error
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
         at java.lang.Boolean.compareTo(Boolean.java:26)
         at com.crystaldecisions.sdk.occa.report.lib.ClonableMap.hasContent(ClonableMap.java:112)
         at com.crystaldecisions.client.helper.CloneUtil.hasContent(CloneUtil.java:135)
         at com.crystaldecisions.sdk.occa.report.data.ConnectionInfo.hasContent(SourceFile:151)
         at com.crystaldecisions.client.helper.CloneUtil.hasContent(CloneUtil.java:135)
         at com.crystaldecisions.sdk.occa.report.data.Table.hasContent(SourceFile:286)
         at com.crystaldecisions.sdk.occa.report.data.Procedure.hasContent(SourceFile:212)
         at com.crystaldecisions.sdk.occa.report.lib.ArrayListMerger.haveMatchingContent(ArrayListMerger.java:232)
         at com.crystaldecisions.sdk.occa.report.lib.ArrayListMerger.mergePass(ArrayListMerger.java:138)
         at com.crystaldecisions.sdk.occa.report.lib.ArrayListMerger.merge(ArrayListMerger.java:86)
         at com.crystaldecisions.sdk.occa.report.lib.ControllableList.copyTo(ControllableList.java:68)
         at com.crystaldecisions.sdk.occa.report.data.Database.copyTo(SourceFile:105)
         at com.crystaldecisions.sdk.occa.report.lib.ControllableHelper.copyToPreservingReferences(ControllableHelper.java:153)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.a(SourceFile:2556)
         at com.crystaldecisions.sdk.occa.report.application.b9.onDataSourceChanging(SourceFile:315)
         at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:971)
         at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:4078)
         at com.crystaldecisions.sdk.occa.report.application.bv.new(SourceFile:121)
         at com.crystaldecisions.sdk.occa.report.application.bv.int(SourceFile:91)
         at com.crystaldecisions.proxy.remoteagent.UndoUnitBase.performDo(SourceFile:151)
         at com.crystaldecisions.proxy.remoteagent.UndoUnitBase.a(SourceFile:106)
         at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:2159)
         at com.crystaldecisions.sdk.occa.report.application.DatabaseController.mapFields(SourceFile:4061)
         at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:3914)
         at com.crystaldecisions.sdk.occa.report.application.DatabaseController.replaceConnection(SourceFile:3880)
         at
    Please advice if Stored procedures and packages are supported in CR4E ?

    Hi, Jack76,
    According to the [CR4E Release Notes|http://help.sap.com/businessobject/product_guides/cr4E/en/cr4e_relnotes_en.pdf] (available from the [CR4E Download page|http://www.businessobjects.com/campaigns/forms/downloads/crystal/eclipse/datasave.asp]), stored procedures are supported, as long as they don't use parameters that need null values.
    I don't see any references to packages.
    Bryan

  • Calling of stored procedure in package

    Hi,
    I have one stored procedure A. And one package of name P1.
    I have execute previlage of package but not having any previlge of stored procedure.
    and In package P1 stored procedure A is called. then this packege is work or it will genrate an Error?

    Oracle users - userA, userB
    Stored procedure - procedure1
    Package - package1
    Who is owner of procedure1 and package1?
    Which privileges of userA/userB on procedure1 and package1?

  • Administering Stored Procedures and Packages

    I've read about WRAP utility but I don't know exactly what's it about. Here you are what ýI've read:ý
    The code used to create the procedure ,package ,or function is available in the dictionary ýviews DBA_Source ,All_Source,and user_source except when you create them with the ýWRAP utility .the WRAP utility generates encrypted code, which only the Oracle server ýcan interpret .ý
    does any one have any idea .
    Thanks in advance

    Generally, one uses the WRAP utility when
    - You are delivering code to a third party
    - You want to ensure that the third party isn't able to decompile your code.
    If you built a CRM application with stored procedures and packages and you started selling that commercially, for example, you would use the WRAP utility to ensure that competitors couldn't reverse engineer your code and see how you did things.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How to check performance for Stored procedure or Package.

    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.

    user13483989 wrote:
    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.Oracle has provided set of Tools to monitor the Performance.
    Profilers being one of them; If you wish to understand more on PL/SQL Optimization, please read PL/SQL Optimization and Tuning.
    See example of DBMS_PROFILER.
    See example of PLSQL Hierarchial Profiler

  • Please help in Stored procedure? Psoting third time Urgent!!!

    Hi,
    We are running websphere3.5.3 on AS/400 machine with DB2Connect as local database.
    I am using com.ibm.db2.jdbc.app.DB2Driver
    We are trying to execute a servlet with stroedprocedure in it.
    In the bottom, I included complete error. Can some one help me? I tried so many things but nothing is working. Infact I could execute other storedprocedure which have hard code input values and outputvalues.
    Same stored procedure is working fine in coldfusion
    Following is creation, code, complete error of storedprocedure.
    I greatly appreciate your help.
    Thanks
    How we created stored procedure is
    create procedure fmgdata.test1
    in puserid char(10), in psuppno dec(7,0),in pitemno dec(5,0),out pmean dec(15,5),out pmedian dec(7,2), out
    pmode dec(7,2), out psamplefx dec(5,0), out pfmgdeal dec(7,2), out pfmgfist dec(7,2),out wrkdatmdy1 char(8),
    out wrkdatmdy2 char(8)
    language rpgle
    NOT DETERMINISTIC
    EXTERNAL NAME fmgdata.rdg002cf
    My code:
    public class storedProcServlet extends HttpServlet
    * Handle the GET Method
    public void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    PrintWriter output;
    String title = "Test Servlet2";
    // set the content type
    resp.setContentType("text/html");
    // write the output
    output = resp.getWriter();
    HttpSession session = req.getSession(true);
    output.println("<HTML><HEAD><TITLE>");
    output.println(title);
    output.println("</TITLE></HEAD><BODY>");
    // load the Db2driver bridge by referencing it
    try
    Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
    catch (Exception e)
    output.println("<P>Failed to load DB2driver.");
    return;
    output.println("<P>Loaded DB2driver.");
    String url = "jdbc:db2://s105k4tm//FMGDATA//SYSDATA//FMGLIB//SYSLIB//*USRLBL//QSYS//aaa";
    // get a connection
    try
    CallableStatement cstmt = null;
    ResultSet resultset = null;
    Connection con = DriverManager.getConnection(
    url, "QSECOFR", "wasadmin"); // User Name: sa, Password: "
    cstmt = con.prepareCall ("{call FMGDATA.test1(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
    if(cstmt == null)
    output.println("problem while callable statement");
    else
    output.println("create callable statement is Ok");
    output.println("Before 1");
    cstmt.setString(1,"MILAR");
    output.println("Before 2");
    cstmt.setDouble(2,21000);
    output.println("Before 3");
    cstmt.setDouble(3,65886);
    output.println("Before 4");
    cstmt.registerOutParameter(4, java.sql.Types.DOUBLE);
    output.println("Before 5");
    cstmt.registerOutParameter(5, java.sql.Types.DOUBLE);
    output.println("Before 6");
    cstmt.registerOutParameter(6, java.sql.Types.DOUBLE);
    output.println("Before 7");
    cstmt.registerOutParameter(7, java.sql.Types.DOUBLE);
    output.println("Before 8");
    cstmt.registerOutParameter(8, java.sql.Types.DOUBLE);
    output.println("Before 9");
    cstmt.registerOutParameter(9, java.sql.Types.DOUBLE);
    output.println("Before 10");
    cstmt.registerOutParameter(10, java.sql.Types.CHAR);
    output.println("Before 11");
    cstmt.registerOutParameter(11, java.sql.Types.CHAR);
    output.println("After 11");
    output.println("Before execute");
    cstmt.execute();
    output.println("After execute");
    catch (Exception e)
    e.printStackTrace(output);
    output.println("<P>This is output from a Stored Procedure Servlet.");
    output.println("</BODY></HTML>");
    output.close();
    //Handle the POST method. To handle POST, we will simple pass the request to the GET method
    public void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    doGet(req,resp);
    error
    Loaded DB2driver.
    create callable statement is Ok
    Before 1 Before 2 Before 3 Before 4 Before 5 Before 6 Before 7 Before 8 Before 9 Before 10 Before 11 After 11 Before execute
    com.ibm.db2.jdbc.app.DB2SQLException2: Trigger program or external routine detected an error. java/lang/Throwable.(Ljava/lang/String;)V+4 (Throwable.java:94) java/sql/SQLException.(Ljava/lang/String;Ljava/lang/String;I)V+1 (SQLException.java:43) com/ibm/db2/jdbc/app/DB2SQLException2.(Ljava/lang/String;Ljava/lang/String;I)V+1 (DB2SQLException2.java:300) com/ibm/db2/jdbc/app/DB2PreparedStatementRuntimeImpl.execute(II)I+40 (DB2PreparedStatementRuntimeImpl.java:387) com/ibm/db2/jdbc/app/DB2PreparedStatement.execute()Z+28 (DB2PreparedStatement.java:1381) storedProcServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+0 (storedProcServlet.java:19) javax/servlet/http/HttpServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+32 (HttpServlet.java:740) javax/servlet/http/HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+25 (HttpServlet.java:853) com/ibm/servlet/engine/webapp/StrictServletInstance.doService(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+21 (ServletManager.java:626) com/ibm/servlet/engine/webapp/StrictLifecycleServlet._service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+46 (StrictLifecycleServlet.java:160) com/ibm/servlet/engine/webapp/ServletInstance.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Lcom/ibm/servlet/engine/webapp/WebAppServletInvocationEvent;)V+186 (ServletManager.java:360) com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.handleWebAppDispatch(Lcom/ibm/servlet/engine/webapp/WebAppRequest;Ljavax/servlet/http/HttpServletResponse;Z)V+771 (WebAppRequestDispatcher.java:404) com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.dispatch(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Z)V+443 (WebAppRequestDispatcher.java:203) com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.forward(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+105 (WebAppRequestDispatcher.java:107) com/ibm/servlet/engine/srt/WebAppInvoker.handleInvocationHook(Ljava/lang/Object;)V+127 (WebAppInvoker.java:77) com/ibm/servlet/engine/invocation/CachedInvocation.handleInvocation(Ljava/lang/Object;)V+25 (CachedInvocation.java:67) com/ibm/servlet/engine/srp/ServletRequestProcessor.dispatchByURI(Ljava/lang/String;Lcom/ibm/servlet/engine/srp/ISRPConnection;)V+839 (ServletRequestProcessor.java:155) com/ibm/servlet/engine/oselistener/OSEListenerDispatcher.service(Lcom/ibm/servlet/engine/oselistener/api/IOSEConnection;)V+95 (OSEListener.java:300) com/ibm/servlet/engine/oselistener/SQEventListenerImp$ServiceRunnable.run()V+155 (SQEventListenerImp.java:230) com/ibm/servlet/engine/oselistener/SQEventListenerImp.notifySQEvent(Lcom/ibm/servlet/engine/oselistener/api/ISQEvent;)V+184 (SQEventListenerImp.java:104) com/ibm/servlet/engine/oselistener/serverqueue/SQEventSource.notifyEvent(Lcom/ibm/servlet/engine/oselistener/api/SQEventImp;)V+40 (SQEventSource.java:212) com/ibm/servlet/engine/oselistener/serverqueue/SQWrapperEventSource$SelectRunnable.notifyService()V+116 (SQWrapperEventSource.java:353) com/ibm/servlet/engine/oselistener/serverqueue/SQWrapperEventSource$SelectRunnable.run()V+124 (SQWrapperEventSource.java:220) com/ibm/servlet/engine/oselistener/outofproc/OutOfProcThread$CtlRunnable.run()V+104 (OutOfProcThread.java:248) java/lang/Thread.run()V+11 (Thread.java:479)
    This is output from a Stored Procedure Servlet.

    Thanks again Jschell,
    I will try to find out exactly what that stored proc is doing. They are saying this stored proc simply gets the values from database using inputs. No insert, delete or update.
    I am too thinking that sending inputs is giving problems.
    If you have any idea how can i format the inputs please let me know. Do you think any problem with driver??
    I did know the same is working in cold fusion fine. Basically it takes three values as inputs and gives 8 out put vaues. In cold fusion they formatted input such that
    AS/400 can under stand.
    In Cold Fusion they formatted as follows,
    <cfset supplier = Numberformat(supplier,'0000000')>
    <cfset item = Numberformat(item,'00000')>
    Even I am trying to do the same thing. It didn't work.
    I did execute some other simple sps where i give hard coded string as input retrieve int, double, strings as outputs.
    This is how they execute the same in cold fusion
    <cfstoredproc procedure="test1" datasource="#datasource#">          
    <cfprocparam type="In" cfsqltype="CF_SQL_CHAR" variable="puserid" value="#session.fsuser#">
    <cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" variable="psuppno" value="#supplier#">
    <cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" variable="pitemno" value="#item#">
    <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pMean">
         <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pMedian">
              <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pMode">
              <cfprocparam type="Out" cfsqltype="CF_SQL_INTEGER" variable="psamplefx">
              <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pfmgdeal">
              <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pfmgfist">
              <cfprocparam type="Out" cfsqltype="CF_SQL_CHAR" variable="wrkdatmdy1">
              <cfprocparam type="Out" cfsqltype="CF_SQL_CHAR" variable="wrkdatmdy2">          
         </cfstoredproc>
    Thanks for any help,

  • Can't Run Stored Procedure in Package

    Hi,
    I am trying to run a stored procedure that has multiple in and out paramaters. The procedure can only be viewed in my Connections panel by navigating Oher Users | <user> | Packages | <package> | <procedure>
    If I right click <procedure>, the menu items are "Order Members By..." and "Create Unit Test" (greyed out). The ability to "Run" the procedure does not seem possible when it's accessed by user.
    I have been trying to find an example of how to create an anonymous block so that I can run the procedure as a SQL file, but haven't found anything that works.
    Does anyone know how I can execute this procedure from SQL Developer? I am using Version 2.1.1.64.
    Thanks in advance!

    Thanks for replying. I did understand the basics of an anonymous block, but what I didn't understand was how to set the out parameters. I should have been more detailed in my question. However, I did get the answer here:
    http://stackoverflow.com/questions/3991721/run-stored-procedure-in-sql-developer
    Thanks again for replying. I appreciate you taking the time.

  • Help: Using stored procedure to add new record in DB

    I am using stored procedures for a form. In DB, I have select and update procedures work without problems. However, for the insert procedure, it does not seem work right. Here is how things work for the insert procedure:
    1. On the form, I have an add record button, when this button is pressed, it calls the trigger "KEY_CREREC" with "create_record."
    2. A blank record is then shown on form. I then put in some test date. Apparently, this will cause "SYSTEM.STATUS" set to "CHANGED." when calling for commit, it only calls the DB update procedure.
    My question is how to make it call the insert procedure.
    Any suggestions are greatly appreciated.

    I just added to lines in key_commit to check the system.form_status:
    set_alert_property('AL_STOP', alert_message_text,'System Status: '||:system.form_status);
    al_button := show_alert('AL_STOP');
    After do_key('create_record') and some changes in fields, the :system.form_status shows "CHANGED.'
    Just wondering what will make the auto generated insert_procedure for the block to trigger. So far, no problems to do query and update with the DB stored procedure, but the insert does not seem working.
    Any help is greatly appreciated.
    P.S. The new post might be more clear:
    http://forums.oracle.com/forums/thread.jspa?threadID=675578&tstart=0
    Message was edited by:
    WJH

  • Help in stored procedure

    i have a stored procedure in MSSQL which needs to be migrated to oracle 10g,i have got problem related to migration.
    My mssql stored procedure is like as follows:
    create procedure sample(
    var1 varchar(20),
    var2 varchar(20) )
    as
    declare @V_TBL table(col1 varchar(20), col2 varchar(20))
    begin
    insert into @V_TBL(col1,col2)
    select col1,col2 from table1 where col1=@var1 and col2=@var2
    some more logic
    end
    now in oracle how do i create this variable table or some other way is there to solve this?

    > i have got problem related to migration.
    Yep.. and this is to be expected. Why? Because Oracle is different than SQL-Server. And it is because of these differences that the market buys Oracle. Not because Oracle is the same as SQL-Server, but because it is difference.
    The first thing you need to accept that migration is not going to be easy and painless - because of these differences.
    What works and works well in SQL-Server, can spell a performance disaster in Oracle. And vice versa.
    Why are temp tables typically used in SQL-Server and Sybase and Ingres and others? Because these databases have a different concurrency and isolation model than Oracle.
    In these products, Writers can block Readers and Readers can block Writers.
    In Oracle, a Reader will never block a Writer. A Writer will never block a Reader. One Writer will only ever block another Writer when vying for the same row. (and on a very rare occasion, when vying for the same data block that lacks sufficient transaction slots)
    Simple example. I open a cursor [SELECT * FROM emp]. I fetch 10 rows of a 100 rows. You start a transaction. You issue a [DELETE FROM emp] and commit. The EMP table is now empty. I fetch the next set of 10 rows using my cursor. What do I see?
    I see the next 10 rows as the EMP table looked like at the time I opened my cursor. I still see all 100 rows. Because that was The Truth at the time I opened my cursor. Oracle guarantees me a consistent read. No dirty reads.
    So the "tricks" you pulled in SQL-Server to work around the reader and writer blocking issue (a failure of SQL-Server ito providing read consistency), is not applicable in Oracle. And the reasons and methods for using temp tables in SQL-Server is not valid in Oracle.
    So when migrating SQL-Server stored proc code to Oracle.. it is a migration. Which means refactoring design and code. Do not expect to be able to simply port the design or code.

  • Stored procedure in  package return multiple columns from multiple tables

    Hi ,
    Can a single stored procedure return multiple column values from different tables.
    example:
    tabA: col2, tabB:col3,tabC:col4 etc.
    one more question:
    if a stored procedure like to return 10 columns for a particular record from a single table do i need to define a TYPE statement for each colum like
    TYPE col1 is TABLE of varchar
    TYPE col2 is TABLE of varchar
    here i want to return only one row, not many rows.
    thanks

    You can try one procedure with OUT or IN/OUT parameters that collect the values from one or more sql statements.
    CREATE OR REPLACE PROCEDURE P1
    (P_COD IN TABLE.COD%TYPE,
    P_DESC1 OUT TABLE1.DESC1%TYPE,
    P_DESC2 OUT TABLE2.DESC2%TYPE)
    IS
    BEGIN
    SELECT table1.DESC1, table2.DESC2
    INTO P_DESC1, P_DESC2
    FROM TABLE1, table2 WHERE
    table1.COD = P_COD and
    table1.cod = table2.cod ;
    END P1;
    JP

  • Need a help on stored procedure

    I have the sample data like the below.
    Employee Id Key Value
    1 Name Joe
    1 Age 28
    1 Addr Houston
    1 Sex M
         2 Addr Chicago     
    I need to get a result somethin like the below using a stored procedure.
    ID Name Age Addr Sex
    1 Jose 28 Houston M
    2     null     null     Chicago     null
    I need to write a stored proc for this......

    Assuming list of keys is static:
    with t as (
               select 1 employee_id,'Name' key,'Joe' val from dual union all
               select 1,'Age','28' from dual union all
               select 1,'Addr','Houston' from dual union all
               select 1,'Sex','M' from dual union all
               select 2,'Addr','Chicago' from dual
    select  employee_id,
            min(case key when 'Name' then val end) name,
            min(case key when 'Age' then val end) age,
            min(case key when 'Addr' then val end) addr,
            min(case key when 'Sex' then val end) sex
      from  t
      group by employee_id
      order by employee_id
    EMPLOYEE_ID NAME                                AGE     ADDR    SEX
              1 Joe                                 28      Houston M
              2                                             Chicago
    SQL> SY.

  • Help on Stored Procedure!

    Hi,
    I've this table AFM_USERS.
    CREATE TABLE AFM_USERS
    USER_PWD VARCHAR2(64 BYTE),
    USER_NAME VARCHAR2(64 BYTE),
    BAD_LOGIN NUMBER DEFAULT 0
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............0
    JOHN..............JOHN$.............0
    SMITH.............SMITH$............0
    KOSTER............KOSTER$...........0
    I've my application that connect Oracle via ODBC.
    When I connect, for example, with USER_NAME=ADAMS PASSWORD=ADAMS$ into sys.fga_log$ table I get 2 records:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.......TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34.....AFM........AFM_MODS....AFM_MODS.....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    When I connect, for example, with USER_NAME=SMITH PASSWORD=SMITH$ into sys.fga_log$ table I get others 2 records:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.....TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS.......AFM_MODS....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN....01/12/2008 7:15:35,7070...SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS......AFM_MODS....01/12/2008 7:15:38,7067.....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    When I connect, for example, with USER_NAME=SMITH PASSWORD=AAAA(Bad Password) into sys.fga_log$ table I get just one record:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.....TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS.......AFM_MODS....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN....01/12/2008 7:15:35,7070...SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS......AFM_MODS....01/12/2008 7:15:38,7067.....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:16:01,7067.......SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    When I connect, for example, with USER_NAME=KOSTER PASSWORD=BBBBB(Bad Password) into sys.fga_log$ table I get just one record:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.....TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS.......AFM_MODS....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN....01/12/2008 7:15:35,7070...SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS......AFM_MODS....01/12/2008 7:15:38,7067.....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:16:01,7067.......SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN...01/12/2008 7:17:04,7067.......SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):KOSTER
    Now I'd like to create a stored procedure on sys.fga_log$ table that increase or decrease of 1 the COUNTER column of table AFM_USERS with these conditions:
    if I connect not correctly (user o password incorrect) I increase COUNTER of 1 (+1)
    if I connect correctly (user and password correct) I decrease COUNTER of 1 (-1)
    In my case I'd like to get like this:
    When I connect with USER_NAME=ADAMS PASSWORD=ADAMS$ I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$...............-1 -- (-1)
    JOHN..............JOHN$...................0
    SMITH.............SMITH$.................0
    KOSTER............KOSTER$.............0
    When I connect with USER_NAME=SMITH PASSWORD=SMITH$ I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............-1
    JOHN..............JOHN$.................0
    SMITH.............SMITH$..............-1 -- (-1)
    KOSTER............KOSTER$...........0
    When I connect with USER_NAME=SMITH PASSWORD=AAAA(Bad Password) I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............-1
    JOHN..............JOHN$.................0
    SMITH.............SMITH$...............0 -- (+1)
    KOSTER............KOSTER$............0
    When I connect with USER_NAME=SMITH PASSWORD=BBBBB(Bad Password) I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............-1
    JOHN..............JOHN$.................0
    SMITH.............SMITH$...............1 -- (+1)
    KOSTER............KOSTER$...........0
    When I connect with USER_NAME=KOSTER PASSWORD=BBBBB(Bad Password) I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$..............-1
    JOHN..............JOHN$...................0
    SMITH.............SMITH$.................1
    KOSTER............KOSTER$..............1 -- (+1)
    How can I create my stored procedure?
    Thanks in advance.

    Raf Royal wrote:
    Hi,
    I've this table AFM_USERS.You do but we can't see them very well.
    After more than 250 posts on the forum we would expect you to be able to format any code and data on your posts you make here, rather than attempting to pad them out with lots of full-stops..............
    Edit your post and re-post the code/data with {noformat}{noformat} tags around it so that it's readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help in Stored Procedure Required

    Dear All,
    I have an udf in my Sales Order u_EnqNo which has some numbers. I want to have a check if while booking the Sales Order if some particular numbers are there then in the project code field which is in the row level of Sales Order should have project code ending with SP ( Special Project).
    I am trying to make an Stored Procedure but its somehow not working and been asking for SP when already SP is there.
    --Project code for Sales Order - Special Projects
    if  @transaction_type IN (N'A', N'U') AND (@Object_type IN ('17'))
    begin
    if exists (select * from rdr1 b,ordr a
    where b.DocEntry=@list_of_cols_val_tab_del
    and (b.Project is null or b.Project='' or b.Project NOT Like '%%_SP' and a.DocEntry=b.Docentry
    and a.u_EnqNo ='95021729' or a.u_EnqNo ='95021970' or a.u_EnqNo ='95022171' or
    a.u_EnqNo ='95021972' or a.u_EnqNo ='95022210' or a.u_EnqNo ='95017240' or
    a.u_EnqNo ='95010501' or a.u_EnqNo ='95021280' or a.u_EnqNo ='95020277' or
    a.u_EnqNo ='95021957' or a.u_EnqNo ='95017862' or a.u_EnqNo ='95021093' or
    a.u_EnqNo ='95020915' or a.u_EnqNo ='95021907' or a.u_EnqNo ='95015477' or
    a.u_EnqNo ='95100300' or a.u_EnqNo ='95100354' or a.u_EnqNo ='95100349' or
    a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
    a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
    a.u_EnqNo ='95021666' or a.u_EnqNo ='95021519' or a.u_EnqNo ='95022148'))
    begin
    select  @error=10 , @error_message = N' Special Project...Provide Special Project Code with Suffix as SP'
    end
    end
    Kindly advise.
    Regards,
    Swamy

    You did not consider the precedence of the logical operators!
    Try this:
    --Project code for Sales Order - Special Projects
    if  @transaction_type IN (N'A', N'U') AND (@Object_type IN ('17'))
    begin
    if exists (select * from rdr1 b,ordr a
    where b.DocEntry=@list_of_cols_val_tab_del
    and (b.Project is null or b.Project='' or b.Project NOT Like '%%_SP' and a.DocEntry=b.Docentry
    and
    (a.u_EnqNo ='95021729' or a.u_EnqNo ='95021970' or a.u_EnqNo ='95022171' or
    a.u_EnqNo ='95021972' or a.u_EnqNo ='95022210' or a.u_EnqNo ='95017240' or
    a.u_EnqNo ='95010501' or a.u_EnqNo ='95021280' or a.u_EnqNo ='95020277' or
    a.u_EnqNo ='95021957' or a.u_EnqNo ='95017862' or a.u_EnqNo ='95021093' or
    a.u_EnqNo ='95020915' or a.u_EnqNo ='95021907' or a.u_EnqNo ='95015477' or
    a.u_EnqNo ='95100300' or a.u_EnqNo ='95100354' or a.u_EnqNo ='95100349' or
    a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
    a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
    a.u_EnqNo ='95021666' or a.u_EnqNo ='95021519' or a.u_EnqNo ='95022148'
    begin
    select  @error=10 , @error_message = N' Special Project...Provide Special Project Code with Suffix as SP'
    end
    end
    Or you can use a more simple form using this:
    a.u_EnqNo in ('95021729', . . ., '95022148')

  • Urgent Help on Stored Procedure

    Hi,
    Could any one pls help me?
    The following is a stored proc where I'm trying to upload data from different tables into one single table. Queries #1 & #3[within cursor loop] are giving results for each policy nbr but #2 is returning no row which is correct in some occassion. I want the proc to go ahead and insert null values or Zero(either is O.K.) for #2 for all existing values of #1 & #3 for all policy numbers. But the proc is not proceeding further for other policy numbers as soon as it gets no value from #2 for the first policy number. It stops reading cursor for subsequent policy numbers and does no insert into the extract_rpts table. I'm using EXCEPTION handling but not working.
    Regards,
    Manojit.
    CREATE OR REPLACE PROCEDURE proc_upload_extract_data IS
    lv_POLICYNO extract_rpts.POLICYNO%TYPE;
    lv_ORIG_CONTR_CNT extract_rpts.ORIG_CONTR_CNT%TYPE :=0;
    lv_ANN_PMT_SUM_CNT extract_rpts.ANN_PMT_SUM_CNT%TYPE :=0;
    lv_ANN_GROSS_PMT_SUM_VAL extract_rpts.ANN_GROSS_PMT_SUM_VAL :=0;
    lv_stat varchar2(100);
    BEGIN
    /* Get all policy nbrs. */
    DECLARE CURSOR extr_pol IS
    SELECT DISTINCT policyno FROM master1;
    /* Following name will be referred for the cursor */
    get_pol extr_pol%ROWTYPE;
    /* Get all policy numbers from the cursor before extracting report data
    for each of the policies*/
    BEGIN
    OPEN extr_pol;
    LOOP
    FETCH extr_pol INTO get_pol;
    EXIT WHEN extr_pol%NOTFOUND;
    lv_POLICYNO := get_pol.policyno;
    /* 1. Original Contract Number */
    select count(policyno)
    into lv_ORIG_CONTR_CNT
    from master1
    where policyno = lv_POLICYNO
    group by policyno;
    /* 2. Annuity Payment Summation Count */
    select count(trxcode)
    into lv_ANN_PMT_SUM_CNT
    from master3
    where trxcode = 7 and
    policyno = lv_POLICYNO
    group by policyno;
    /* 3. Annuity-Gross Payment Summation Value */
    select sum(d.grosspay)
    into lv_ANN_GROSS_PMT_SUM_VAL
    from master3 c, master4 d
    where c.policyno = lv_POLICYNO and
    c.trxcode = 7 and
    c.policyno = d.policyno and
    c.DATETRXEFF = d.DATETPAY
    group by c.policyno;
    /* Now since the data for the policy number is loaded into local
    variables, it is inserted into the extract_rpts table */
    insert into extract_rpts
    POLICYNO,
    ORIG_CONTR_CNT,
    ANN_PMT_SUM_CNT,
    ANN_GROSS_PMT_SUM_VAL )
    values (
    lv_POLICYNO,
    lv_ORIG_CONTR_CNT,
    lv_ANN_PMT_SUM_CNT,
    lv_ANN_GROSS_PMT_SUM_VAL
    END LOOP; /* for the cursor extr_pol */
    CLOSE extr_pol;
    END;
    EXCEPTION
    WHEN OTHERS THEN
    lv_stat := 'Correct Record';
    commit;
    END; /* of the procedure proc_upload_extract_data */
    null

    Hi Manojit,
    Unfortunatly your question is not
    related to Oracle Spatial.
    Please try posting this to metalink.
    Thanks.
    Dan

  • Oracle stored procedure in a package

    Hello,
    I'm working on a Web service -> XI -> Oracle scenario.
    In the receiver side I'm using JDBC Adapter to call to stored procedure.
    I have stored procedure in a package.
    For example: package "price_list_pk" and stored procedure "is_pl".
    When I try to enter the stored procedure path to XML tags I need to separate between the package and the stored procedure with dot "." and dot is not allowed in XML tag.
    I want to now if you have answer for this problem
    Have other way to work with stored procedure in packages?
    Elad

    Hey everyone,
    What Elad means is that in the XML structure of JDBC there are 2 places you define the DB\SP name:
    1. Defined in the structure itself as an element name. (DT)
    2. Mapped with a constant to a subelement called TABLE. (MM)
    The MM shouldn't be a problem as a value can get the dot character.
    But, in the DT structure, because you define here a XSD (XML structure) there is a problem naming the element with the dot character being part of the name as this character is not accepted in a XML tagname.
    The right question is if anyone knows of a special XML attribute with which you could define that the element name would contain a dot character? Or else a creative way to call a Stored Procedure inside a Package despite the disabilities above?
    Ben

Maybe you are looking for

  • Mid 2010 MacBook Pro battery capacity at 89% with 64 cycles

    Hello everyone, I have a 13" mid 2010 MacBook Pro that I got around Christmas time. I downloaded coconutbattery a couple days ago and when i used it then My battery capacity had been 91%. So I thought that this was odd because of how new the computer

  • I recently downloaded Word Lens for my iPhone 5S. However when i go to do the in app purchases i don't see any languages available.

    I recently downloaded Word Lens for my iPhone 5S. However when i go to do the in app purchases i don't see any languages available.

  • Window Maker and xorg 7.0

    Can you run Window Maker with new xorg? Each time I try to run it I see just window with information that Window Maker segfaulted. I deleted GNUstep in my home, then called wmaker.conf, but that didn't help. Yesterday I updated Window Maker, because

  • Dual Monitors won't sleep

    hi, i just added an older cintiq 21ux to my mac pro. the other monitor is an acer h233h. since adding the cintiq, neither monitor will go to sleep at the set time (15min). i've tried repairing permissions during a safe boot, re-installing the cintiq

  • Transaction timed out with oracle 9i

    Hi, I am working with weblogic6.1. Sometimes (very seldom) I have a problem which I don't undserstand. The transaction stops and and after some time I get TimedOutException. This time it happend in the findByPrimaryKey of a CMP Entity bean. I have th