473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calling a Stored Procedure via a trigger

129 100+
Hi we have created a stored procedure to check the dates entered into a lease table does not overlap dates already stored for a lease. However when inserting overlapping lease dates, it allows us to insert this entry into the lease table, we was thinking of doing a trigger to execute the stored procedure to prevent a row being inserted into the lease table if there are overlapping dates:

The code we have for stored procedure is:
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PROCEDURE p_check_lease_date (
  2.       p_lease_id           Lease.LeaseID%TYPE,
  3.       p_property_id       Lease.PropertyID%TYPE,      
  4.       p_room_id            Lease.RoomID%TYPE,    
  5.       p_start_date         Lease.StartDate%TYPE,      
  6.       p_end_date           Lease.EndDate%TYPE,               
  7.       p_error        OUT   VARCHAR2                   
  8.    )
  9.  
  10.    IS
  11.       v_no_of_rooms  NUMBER;                 
  12.  
  13.    BEGIN
  14.  
  15.  
  16.       IF p_start_date > p_end_date
  17.       THEN
  18.          p_error := 'End date cannot be earlier than start date';
  19.       END IF;
  20.  
  21.  
  22.       SELECT COUNT (*)
  23.         INTO v_no_of_rooms
  24.         FROM Lease
  25.  
  26.        WHERE (   (    p_start_date >= Lease.StartDate
  27.                   AND p_start_date <
  28.                                   NVL (Lease.EndDate, SYSDATE)
  29.                  )
  30.  
  31.               OR (    p_start_date <= Lease.StartDate
  32.                   AND p_end_date > Lease.StartDate
  33.                  )
  34.              )
  35.          AND Lease.RoomID = p_room_id
  36.      AND Lease.PropertyID = p_property_id
  37.          AND Lease.LeaseID != p_lease_id;                  
  38.  
  39.       IF v_no_of_rooms > 0
  40.       THEN
  41.          p_error := 'An Overlapping Room Booking Exists for these dates';
  42.       END IF;
  43.  
  44.      EXCEPTION
  45.       WHEN OTHERS
  46.       THEN
  47.          p_error :=
  48.                'System Error '
  49.             || SUBSTR (TO_CHAR (SQLCODE) || ' ' || SQLERRM, 1, 100);
  50.  
  51. END;
This is the code for our attempt of a trigger but it doesnt create properly:

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE TRIGGER trg_Double_Lease_Error
  2. BEFORE INSERT OR UPDATE OF EndDate ON Lease
  3. FOR EACH ROW
  4.  
  5. BEGIN
  6. call p_check_lease_date(:new.LeaseID); 
  7.  
  8. END;
Any help would be appreciated.
Apr 1 '08 #1
3 26560
debasisdas
8,127 Expert 4TB
Your procedure contains 6 pameters but you are passing only one to call it in trigger.
Apr 2 '08 #2
Constantine AI
129 100+
Your procedure contains 6 pameters but you are passing only one to call it in trigger.
We have altered the code to this:

CALL p_check_lease_date(:NEW.LeaseID, :NEWPropertyID, :NEWRoomID, :NEWStartDate, :NEWEndDate, :NEW:p_error );

but it doesnt like the OUT parameter in the line of this trigger and doesnt like it if we take it out either, do you know how we should show the OUT parameter in this line?
Apr 2 '08 #3
debasisdas
8,127 Expert 4TB
Out parameter is used to return value . You can't pass any value to that.
Apr 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
0
by: JN | last post by:
Hello, I'm having problem calling stored procedures from Visual FoxPro database. I got the following exception error: "System.Data.OleDb.OleDbException: Unrecognized command verb" It seems...
6
by: Scott McNair | last post by:
Hi all, I'm having problems calling a stored procedure from within my code. If I execute the SP manually from a Query Analyzer window it runs without a hitch, but it seems it doesn't even fire...
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
5
by: marcsirois | last post by:
I am maintaining an application where most of the business rules are in Triggers, Stored Procedures and User Defined Functions. When a bug arises, it can get very tedious to debug. Today for...
14
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc...
4
by: eighthman11 | last post by:
I'm calling a stored procedure on a sql server from an access application. I just need the stored procedure to run I do not need any data returned from the stored procedure to my Access...
2
by: =?Utf-8?B?YW5vb3A=?= | last post by:
Hello, I have a stored procedure named as usp_CheckLogin with two parameters as @usID, @Password also values of these parameters are to be extracted using Request.Form from the fields in...
3
by: yinzara | last post by:
I have the following trigger that calls a DB2 stored procedure: DROP TRIGGER GGWU.TRI_A_MULTI_PROP@ CREATE TRIGGER GGWU.TRI_A_MULTI_PROP AFTER INSERT ON GGWU.MULTIPLIER_PROPERTY REFERENCING ...
6
Soniad
by: Soniad | last post by:
Hello, I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.