Advertisement
Fendhio

Fn Hasil Pertanyaan PgSQL

Nov 12th, 2021
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- FUNCTION: public.fn_insert_pelamar_data_pribadi_pertanyaan(character varying, character varying, text, character varying, text, character varying)
  2.  
  3. -- DROP FUNCTION public.fn_insert_pelamar_data_pribadi_pertanyaan(character varying, character varying, text, character varying, text, character varying);
  4.  
  5. CREATE OR REPLACE FUNCTION public.fn_insert_pelamar_data_pribadi_pertanyaan(
  6.     character varying,
  7.     character varying,
  8.     text,
  9.     character varying,
  10.     text,
  11.     character varying)
  12.     RETURNS character varying
  13.     LANGUAGE 'plpgsql'
  14.     COST 100
  15.     VOLATILE PARALLEL UNSAFE
  16. AS $BODY$
  17. DECLARE r RECORD;  
  18. DECLARE
  19.  
  20.     v_nik               ALIAS FOR $1;
  21.     v_kd_pert           ALIAS FOR $2;
  22.     v_nm_pert           ALIAS FOR $3;
  23.     v_jawaban           ALIAS FOR $4;
  24.     v_jwb_detail        ALIAS FOR $5;
  25.     v_nm_ins            ALIAS FOR $6;
  26.  
  27.     rcd record;
  28.    
  29. BEGIN
  30.  
  31.     select nik,kode_pertanyaan
  32.     into rcd
  33.     from hr_pelamar_pertanyaan_hasil
  34.     where  nik=v_nik and kode_pertanyaan=v_kd_pert;
  35.    
  36.     IF rcd.nik is not null THEN
  37.    
  38.         update  hr_pelamar_pertanyaan_hasil set jawaban=v_jawaban,
  39.         jawaban_detail=v_jwb_detail
  40.         where nik=v_nik
  41.         and kode_pertanyaan=v_kd_pert;
  42.        
  43.     return 'Update data pertanyaan pelamar berhasil';
  44.     else
  45.  
  46.         INSERT INTO hr_pelamar_pertanyaan_hasil(nik,
  47.         kode_pertanyaan,nama_pertanyaan,jawaban,jawaban_detail,nama_ins)
  48.         values (v_nik,v_kd_pert,v_nm_pert,v_jawaban,v_jwb_detail,v_nm_ins);
  49.        
  50.     return 'Data pertanyaan pelamar berhasil dimasukkan';
  51.     END IF;
  52.     return null;
  53.    
  54. /*
  55. select fn_insert_pelamar_data_pribadi_pertanyaan
  56. (v_nik,v_kd_pert,v_nm_pert,v_jawaban,v_jwb_detail,v_nm_ins)
  57.  
  58. */
  59.  
  60.    
  61. END
  62. $BODY$;
  63.  
  64. ALTER FUNCTION public.fn_insert_pelamar_data_pribadi_pertanyaan(character varying, character varying, text, character varying, text, character varying)
  65.     OWNER TO postgres;
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement