thelittlewozniak

Untitled

Dec 28th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.20 KB | None | 0 0
  1. -- -----------------------------------------------------
  2. -- CREATE POSTPACKAGE
  3. -- -----------------------------------------------------
  4. CREATE OR REPLACE PACKAGE POSTPACKAGE
  5. IS
  6. TYPE find_cursor
  7. IS
  8.   REF
  9.   CURSOR;
  10.     FUNCTION ADD(
  11.         p_data POST.data%TYPE,
  12.         p_type POST.type%TYPE,
  13.         p_postDate POST.postDate%TYPE,
  14.         p_iduser POST.iduser%TYPE )
  15.       RETURN NUMBER;
  16.     PROCEDURE del(
  17.         p_idpost POST.idpost%TYPE ) ;
  18.     PROCEDURE upd(
  19.         p_idpost POST.idpost%TYPE,
  20.         p_data POST.data%TYPE,
  21.         p_type POST.type%TYPE,
  22.         p_postDate POST.postDate%TYPE,
  23.         p_iduser POST.iduser%TYPE ) ;
  24.     FUNCTION get(
  25.         p_idpost POST.idpost%TYPE )
  26.       RETURN find_cursor;
  27.     FUNCTION getAll
  28.       RETURN find_cursor;
  29.   END POSTPACKAGE;
  30.   /
  31. CREATE OR REPLACE PACKAGE BODY POSTPACKAGE
  32. AS
  33.   FUNCTION ADD(
  34.       p_data POST.data%TYPE,
  35.       p_type POST.type%TYPE,
  36.       p_postDate POST.postDate%TYPE,
  37.       p_iduser POST.iduser%TYPE )
  38.     RETURN NUMBER
  39.   AS
  40.     usrid NUMBER;
  41.   BEGIN
  42.     INSERT
  43.     INTO POST
  44.       (
  45.         data,
  46.         TYPE,
  47.         postDate,
  48.         iduser
  49.       )
  50.       VALUES
  51.       (
  52.         p_data,
  53.         p_type,
  54.         p_postDate,
  55.         p_iduser
  56.       )
  57.     RETURNING iduser
  58.     INTO usrid;
  59.   RETURN usrid;
  60. END ADD;
  61.   PROCEDURE del
  62.     (
  63.       p_idpost POST.idpost%TYPE
  64.     )
  65.   AS
  66.   BEGIN
  67.     DELETE FROM POST WHERE idpost=p_idpost;
  68.   END del;
  69.   PROCEDURE upd(
  70.       p_idpost POST.idpost%TYPE,
  71.       p_data POST.data%TYPE,
  72.       p_type POST.type%TYPE,
  73.       p_postDate POST.postDate%TYPE,
  74.       p_iduser POST.iduser%TYPE )
  75.   AS
  76.   BEGIN
  77.     UPDATE POST
  78.     SET data     =p_data,
  79.       TYPE       =p_type,
  80.       postDate   =p_postDate,
  81.       iduser     =p_iduser
  82.     WHERE idpost =p_idpost;
  83.   END upd;
  84.   FUNCTION get(
  85.       p_idpost POST.idpost%TYPE)
  86.     RETURN find_cursor
  87.   AS
  88.     post_cursor find_cursor;
  89.   BEGIN
  90.     OPEN post_cursor FOR SELECT idpost,
  91.     data,
  92.   TYPE,
  93.   postDate,
  94.   iduser FROM POST WHERE idpost=p_idpost;
  95.   RETURN post_cursor;
  96. END get;
  97.   FUNCTION getAll
  98.     RETURN find_cursor
  99.   AS
  100.     post_cursor find_cursor;
  101.   BEGIN
  102.     OPEN post_cursor FOR SELECT idpost,
  103.     data,
  104.   TYPE,
  105.   postDate,
  106.   iduser FROM POST;
  107.   RETURN post_cursor;
  108. END getAll;
  109. END POSTPACKAGE;
Advertisement