Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. create table stage_complaint(
  2. complaint_key integer,
  3. complaint_id integer,
  4. cancellation_reason varchar(255),
  5. complaint_status varchar(255),
  6. complaint_type varchar(255),
  7. compentation_status varchar(255)
  8. );
  9.  
  10. ALTER TABLE stage_complaint ADD CONSTRAINT stg_complaint_pk PRIMARY KEY (complaint_key);
  11.  
  12. desc stage_complaint;
  13.  
  14. DESC complaint;
  15.  
  16. CREATE SEQUENCE Complaint_seq
  17. START WITH 1
  18. INCREMENT BY 1
  19. MAXVALUE 99999999
  20. MINVALUE 1
  21. NOCYCLE;
  22.  
  23. UPDATE stage_complaint SET complaint_key = Complaint_seq.NEXTVAL;
  24.  
  25. CREATE TRIGGER Complaint_trigger
  26. BEFORE INSERT ON stage_complaint
  27. FOR EACH ROW
  28. BEGIN
  29. SELECT Complaint_seq.nextval
  30. INTO :new.complaint_key
  31. FROM dual;
  32. END;
  33.  
  34. MERGE INTO stage_complaint SC
  35. USING (SELECT complaint_id,description,complaint_status,complaint_type,compensation_amnt FROM complaint) C
  36. ON (
  37. SC.complaint_id = C.complaint_id
  38. )
  39. WHEN MATCHED THEN
  40. UPDATE SET
  41. SC.cancellation_reason = C.description,
  42. SC.complaint_status = C.complaint_status,
  43. SC.complaint_type = C.complaint_type,
  44. SC.compentation_status = C.compensation_amnt
  45. WHEN NOT MATCHED THEN
  46. INSERT VALUES (Complaint_seq.NEXTVAL,C.complaint_id, C.description, C.complaint_status,C.complaint_type,C.compensation_amnt);
  47.  
  48. select * from stage_complaint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement