Advertisement
joaofabioma

Conversao Sim Nao

Jun 24th, 2025
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PostgreSQL 0.69 KB | Source Code | 0 0
  1. CREATE TYPE simnaobool AS ENUM ('Sim', 'Não'); -- (TRUE=Sim, FALSE=Não)
  2. CREATE TYPE simnaoint AS ENUM ('Sim', 'Não'); -- (1=Sim, 0=Não)
  3.  
  4. CREATE OR REPLACE FUNCTION bool2simnao(boolean)
  5. RETURNS simnaobool AS $$
  6. BEGIN
  7.   RETURN CASE WHEN $1 THEN 'Sim'::simnaobool ELSE 'Não'::simnaobool END;
  8. END;
  9. $$ LANGUAGE plpgsql IMMUTABLE;
  10.  
  11. CREATE OR REPLACE FUNCTION int2simnao(integer)
  12. RETURNS simnaoint AS $$
  13. BEGIN
  14.   RETURN CASE WHEN $1 = 1 THEN 'Sim'::simnaoint ELSE 'Inativo'::simnaoint END;
  15. END;
  16. $$ LANGUAGE plpgsql IMMUTABLE;
  17.  
  18. CREATE CAST (boolean AS simnaobool) WITH FUNCTION bool2simnao(boolean) AS IMPLICIT;
  19. CREATE CAST (integer AS simnaoint) WITH FUNCTION int2simnao(integer) AS IMPLICIT;
  20.  
Tags: sim Nao simnao
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement