Question

In: Computer Science

SQL Trigger problem When attemptiing to Create or Replace a trigger I get the error "sql...

SQL Trigger problem

When attemptiing to Create or Replace a trigger I get the error "sql warning trigger created with compilation errors".

Trigger:

CREATE OR REPLACE TRIGGER Late_Fees
after UPDATE
ON InventoryItem
FOR EACH ROW

DECLARE

late_fee number;
num_days number;
BEGIN
num_days:= to_date(:old.ReturnDate)-TO_DATE(:old.DateDue);
select IntValue into late_fee from ApplicationSettings where Setting='Daily Late Fee';
:new.fee := (late_fee)*(num_days);

END;
/

commit;

Table:

create table Rental(
INVID int Primary key,
LoanDate date,
PatronID int,
DueDate date,
ReturnDate date,
constraint PatronID_FK Foreign key (PatronID) references Patrons(PatronID));

Test Input:

insert into rental
values ('1345', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1345', '2020-04-10', '000', '2020-04-17', '2020-04-17');
insert into rental
values ('1234', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1245', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1345', '2020-08-14', '0001', '2020-08-21', '2020-08-20');
insert into rental
values ('1265', '2020-09-01', '0001', '2020-09-08', '2020-09-10');

Solutions

Expert Solution

SOLUTION

CREATE OR REPLACE TRIGGER EMP_DEL
AFTER DELETE ON EMPLOYEES
FOR EACH ROW
BEGIN
INSERT INTO EMP_TEMP
(EMPLOYEE_ID,EMPLOYEE_NAME,JOB_ID,JOB_DESCRIPTION,H
OD,HIREDATE,SALARY,DEPARTMENT_ID)
VALUES (:OLD.EMPLOYEE_ID, :OLD.EMPLOYEE_NAME, :OLD.JOB_ID,
:OLD.JOB_DESCRIPTION, :OLD.HOD, :OLD.HIREDATE, :OLD.SALARY,
:OLD.DEPARTMENT_ID);
END;

GIVEN THAT

SQL Trigger problem

When attemptiing to Create or Replace a trigger I get the error "sql warning trigger created with compilation errors".

Trigger:

CREATE OR REPLACE TRIGGER Late_Fees
after UPDATE
ON InventoryItem
FOR EACH ROW

DECLARE

late_fee number;
num_days number;
BEGIN
num_days:= to_date(:old.ReturnDate)-TO_DATE(:old.DateDue);
select IntValue into late_fee from ApplicationSettings where Setting='Daily Late Fee';
:new.fee := (late_fee)*(num_days);

END;
/

commit;

Table:

create table Rental(
INVID int Primary key,
LoanDate date,
PatronID int,
DueDate date,
ReturnDate date,
constraint PatronID_FK Foreign key (PatronID) references Patrons(PatronID));

Test Input:

insert into rental
values ('1345', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1345', '2020-04-10', '000', '2020-04-17', '2020-04-17');
insert into rental
values ('1234', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1245', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1345', '2020-08-14', '0001', '2020-08-21', '2020-08-20');
insert into rental
values ('1265', '2020-09-01', '0001', '2020-09-08', '2020-09-10');

FOR EXAMPLE:

/* Libary Design Exercise 
   version that adds members and distinguishes borrowable from 
   un-borrowable items
   
   Things to Note:
   - we added an IBorrowable interface that applies to Books and DVDs
   - each of Book and DVD now has a lateFee method
   - in the Examples class, if we want to check out the result of
     finding an item, we need to tell Java that the item is indeed 
     Borrowable.  We do this through a _cast_ (see notes for details)
    
   Ask yourself:
   - Why did we need the IBorrowable interface?
*/
import java.util.LinkedList;

class Library {
  LinkedList<LibItem> holdings = new LinkedList<LibItem>();

  // constructor
  Library() {}
  
  // add a new book to the library
  Library addItem(LibItem newItem) {
    holdings.add(newItem);
    return this;
  }
  
  // find a book by its title
  // assumes the title is in the library 
  //   (unrealistic, but what we know how to do so far)
  LibItem findTitle(String atitle) {
    for (LibItem item : holdings) {
      if (item.hasTitle(atitle)) {
        return item;
      }
    }
    // the compiler needs to return something if the book 
    //   isn't found. We can use null for this (we really
    //   should handle the error explicitly, but we haven't
    //   covered how to do that yet).
    return null; 
  }
}

abstract class LibItem {
  String title;
  String location;
   
  LibItem(String title, String location) {
    this.title = title;
    this.location = location;
  }
  
  // check whether item has a given title
  public boolean hasTitle(String atitle) {
    return this.title.equals(atitle);
  }
  
  // tell Java how to display this object when printed
  //  here, we put "obj" in front of the title (to tell strings from objects)
  public String toString() {
    return "Obj:"+this.title;
  }
}

abstract class CirculatingItem extends LibItem implements IBorrowable {
  int timesOut = 0;
  boolean isAvailable = true;
  
  CirculatingItem(String title, String location) {
    super(title, location);
  }
  
  // mark an item as checked out of the library
  public LibItem checkOut() {
    this.isAvailable = false;
    this.timesOut = this.timesOut + 1;
    return this;
  }
  
  // mark an item as checked in at the library
  public LibItem checkIn() {
    this.isAvailable = true;
    return this;
  }
}

// A class for books in a library
class Book extends CirculatingItem {
  
  // constructor
  Book(String title, String callNum) {
    super(title, callNum);
  }
  
  // book late fee is 25 cents per day
  public double lateFee(int daysOver) {
    return daysOver * .25;
  }
}

class DVD extends CirculatingItem {
  
  // Constructor 
  DVD (String title) {
    super(title,"Circulation Desk");
  }
  
  // DVD late fee is 5 dollars up to 3 days then 20 dollars above that
  public double lateFee(int daysOver) {
    if (daysOver <= 3) {
      return 5;
    } else {
      return 20;
    }
  }
}

// reference materials that cannot be checked out
class Reference extends LibItem {
  
  //constructor
  Reference(String title) {
    super(title, "Reference Shelf");
  }
}

class LibMember {
  String name;
  double feesOwed = 0;
  LinkedList<IBorrowable> checkedOut = new LinkedList<IBorrowable>();
  
  // constructor
  LibMember(String name) {
    this.name = name;
  }   
}

// interface for items that can be checked out
interface IBorrowable {
  // computes late fee assess given how many days overdue the item is
  public double lateFee(int daysOver);
}

class Examples {
  Library theLibrary = new Library();
  LibMember k = new LibMember("Kathi");
  DVD swDVD = new DVD("Star Wars 3");
  
  Examples(){
    // can add named objects or create new as you go
    theLibrary.addItem(swDVD); 
    theLibrary.addItem(new Book("Effective Java", "QA76.73 J38 B57"));
    theLibrary.addItem(new Book("Alice in Wonderland", "PR4611 A7"));
    theLibrary.addItem(new Book("Freakonomics", "HB74 P8 L479"));
    theLibrary.addItem(new Reference("Dictionary"));
  }
  
  /* try this expressions
   *   k.borrowItem(theLibary.findTitle("Freakonomics"))
   * What is the compiler concerned about? The fix is to type
   *   k.borrowItem((IBorrowable) theLibary.findTitle("Freakonomics"))
   * See the notes for a discussion about this (casting)
   */
  
}

Related Solutions

SQL- Trigger I have two tables (below) I need to write a trigger that would delete...
SQL- Trigger I have two tables (below) I need to write a trigger that would delete everything for a pid from the Appt table if the pid is deleted from the patient table. Create table Appt(                 pid numeric Foreign Key references patient(pid),                 ptname varchar(50) Foreign Key references patient(name),                 dob date Foreign Key references patient(dob),                 dr varchar(20),                 appdate date,                 apptime time, ); and Create table Patient(                 pid numeric primary key,                 name varchar(50),                ...
BSTree.java:99: error: reached end of file while parsing } I get this error when i run...
BSTree.java:99: error: reached end of file while parsing } I get this error when i run this code. can someone help me out? I can't figure out how to make this work. public class BSTree<T extends Comparable<T>> { private BSTreeNode<T> root = null; // TODO: Write an addElement method that inserts generic Nodes into // the generic tree. You will need to use a Comparable Object public boolean isEmpty(){ return root == null; } public int size(){ return node;} public...
I get an error when im trying to run this java program, I would appreciate if...
I get an error when im trying to run this java program, I would appreciate if someone helped me asap, I will make sure to leave a good review. thank you in advance! java class Node public class Node { private char item; private Node next; Object getNext; public Node(){    item = ' '; next = null; } public Node(char newItem) { setItem(newItem); next = null; } public Node(char newItem, Node newNext){ setItem(newItem); setNext(newNext); } public void setItem(char newItem){...
SQL Assignment: Provide a made-up scenario about when a database trigger could be used. There is...
SQL Assignment: Provide a made-up scenario about when a database trigger could be used. There is no need to provide the syntax to create the trigger, as this would differ depending upon the actual design of the database. Only provide the scenario of when a trigger could be used.
Why am I getting this error using 000webhost , but I do not get this error...
Why am I getting this error using 000webhost , but I do not get this error running XAMPP? Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd2/006/14881006/public_html/test/index.php:1) in /storage/ssd2/006/14881006/public_html/test/index.php on line 8 Code is below. ******************************************************************************************************************** <!DOCTYPE html> <?php    //Determine if the submit button has been clicked to set the cookie name and value    if (isset($_POST['name'])){            $cookie_name = $_POST['name'];            $cookie_value = $_POST['value'];            setcookie($cookie_name, $cookie_value,...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
I HAVE THIS PROBLEM: Create a new Project and name it - InClassParticipation3 Get up to...
I HAVE THIS PROBLEM: Create a new Project and name it - InClassParticipation3 Get up to 5 inputs from the user. The user must enter at least 1 number. After the first input, ask them if they would like to input another number, if they say 'yes' get the provided input and multiply it to the other inputs provided by the user. If the user says 'no', do not prompt them to input anymore numbers and then figure out if...
I keep on get a redefinition error and an undefined error. Customer List (1) CustomerList() and...
I keep on get a redefinition error and an undefined error. Customer List (1) CustomerList() and ~CustomerList() - default constructor and destructor. (2) bool addStore(Store*s) - Add an instance of store to the linked list. Return true if successful. (3) Store *removeStore(int ID) - Locate a Store in the list if it exists, remove and return it. (4) Store *getStore(int ID) - Locate a Store in the list and return a pointer to it. (5) bool updateStore(int ID, char *name,...
how can i get the code for this problem in visual basic? Create a Windows Forms...
how can i get the code for this problem in visual basic? Create a Windows Forms applications called ISP (Internet Service Provider) Project. You must enter the number of hours for the month and select your desire ISP package. An ISP has three different subscription packages for it's customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2 per hours. Package B: For $13.95 per month 20 hours of access are provided. Additional...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT