thelittlewozniak

Untitled

Dec 27th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.53 KB | None | 0 0
  1. CREATE OR REPLACE TRIGGER NEW_USER BEFORE
  2.   INSERT ON USERS FOR EACH ROW BEGIN :NEW.iduser:=SEQ_users.NEXTVAL;
  3. END;
  4. /
  5. CREATE OR REPLACE PACKAGE USERPACKAGE
  6. IS
  7. TYPE RFC
  8. IS
  9.   REF
  10.   CURSOR;
  11.     FUNCTION ADD
  12.       (
  13.         firstname USERS.firstname%TYPE,
  14.         lastname USERS.lastname%TYPE,
  15.         address USERS.address%TYPE,
  16.         birthday USERS.birthday%TYPE,
  17.         registerDate USERS.registerDate%TYPE,
  18.         relationship USERS.relationshio%TYPE,
  19.         phoneNumber USERS.phoneNumber%TYPE,
  20.         gender USERS.gender%TYPE,
  21.         interestedIn USERS.interestedIn%TYPE
  22.       )
  23.       RETURN NUMBER;
  24.     PROCEDURE del
  25.       (
  26.         userid USERS.iduser%TYPE
  27.       )
  28.       ;
  29.     PROCEDURE upd
  30.       (
  31.         userid USERS.iduser%TYPE,
  32.         firstname USERS.firstname%TYPE,
  33.         lastname USERS.lastname%TYPE,
  34.         address USERS.address%TYPE,
  35.         birthday USERS.birthday%TYPE,
  36.         registerDate USERS.registerDate%TYPE,
  37.         relationship USERS.relationshio%TYPE,
  38.         phoneNumber USERS.phoneNumber%TYPE,
  39.         gender USERS.gender%TYPE,
  40.         interestedIn USERS.interestedIn%TYPE
  41.       )
  42.       ;
  43.     FUNCTION get
  44.       (
  45.         userid USERS.iduser%TYPE
  46.       )
  47.       RETURN rfc;
  48.     FUNCTION getAll
  49.       RETURN rfc;
  50.   END GETALL;
  51. END USERPACKAGE;
  52. /
  53. CREATE OR REPLACE PACKAGE BODY USERPACKAGE
  54. AS
  55.   FUNCTION ADD
  56.     (
  57.       p_firstname USERS.firstname%TYPE,
  58.       p_lastname USERS.lastname%TYPE,
  59.       p_mail USERS.email%TYPE,
  60.       p_mdp USERS.password%TYPE,
  61.       p_address USERS.address%TYPE,
  62.       p_birthday USERS.birthday%TYPE,
  63.       p_registerDate USERS.registerDate%TYPE,
  64.       p_relationship USERS.relationship%TYPE,
  65.       p_phoneNumber USERS.phoneNumber%TYPE,
  66.       p_gender USERS.gender%TYPE,
  67.       p_interestedIn USERS.interestedIn%TYPE
  68.     )
  69.     RETURN NUMBER
  70.   AS
  71.     User_Existing EXCEPTION;
  72.     p_count       NUMBER;
  73.     usrid         NUMBER;
  74.   BEGIN
  75.     SELECT COUNT(*) INTO p_count FROM USERS WHERE email=p_mail;
  76.   IF p_count > 0 THEN
  77.     RAISE User_Existing;
  78.   ELSE
  79.     INSERT
  80.     INTO USERS
  81.       (
  82.         firstname,
  83.         lastname,
  84.         email,
  85.         password,
  86.         address,
  87.         birthday,
  88.         registerDate,
  89.         relationship,
  90.         phoneNumber,
  91.         gender,
  92.         interestedIn
  93.       )
  94.       VALUES
  95.       (
  96.         p_firstname,
  97.         p_lastname,
  98.         p_mail,
  99.         p_password,
  100.         p_address,
  101.         p_birthday,
  102.         p_registerDate,
  103.         p_relationship,
  104.         p_phoneNumber,
  105.         p_gender,
  106.         p_interestedIn
  107.       )
  108.     RETURNING iduser
  109.     INTO usrid;
  110.   END IF;
  111. RETURN usrid;
  112. END ADD;
Advertisement