Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » PostgreSQL »

como obtener fecha actual

Estas en el tema de como obtener fecha actual en el foro de PostgreSQL en Foros del Web. esta es mi funcion...... CREATE OR REPLACE FUNCTION REC_GER(NUM_PRE1 int, OBS TEXT, PASA BIT, MAT_REV CHAR(3)) RETURNS void AS $BODY$declare begin IF PASA = '1' ...
  #1 (permalink)  
Antiguo 14/05/2007, 08:58
 
Fecha de Ingreso: abril-2007
Mensajes: 27
Antigüedad: 17 años, 1 mes
Puntos: 0
como obtener fecha actual

esta es mi funcion......
CREATE OR REPLACE FUNCTION REC_GER(NUM_PRE1 int,
OBS TEXT,
PASA BIT,
MAT_REV CHAR(3))
RETURNS void AS
$BODY$declare

begin
IF PASA = '1' then
BEGIN
UPDATE PRESTAMO SET OBS_REV = OBS, ESTADO = 'RG', USR_REV = MAT_REV, FEC_REV =(select now()) WHERE NUM_PRE = NUM_PRE1;
END;
ELSE
BEGIN
UPDATE PRESTAMO SET OBS_REV = OBS , ESTADO = 'OG', USR_REV = MAT_REV, FEC_REV =(select now()) WHERE NUM_PRE = NUM_PRE1;
END;
end if;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION REC_GER(NUM_PRE1 int,
OBS TEXT,
PASA BIT,
MAT_REV CHAR(3)) OWNER TO postgres;
ejecuto y me sale lo sgte

ERROR: value too long for type character(3)
Estado SQL:22001
Contexto:SQL statement "UPDATE PRESTAMO SET OBS_REV = $1 , ESTADO = 'RG', USR_REV = $2 , FEC_REV =(select now()) WHERE NUM_PRE = $3 "
PL/pgSQL function "rec_ger" line 6 at SQL statement


como ven los parametros estan pasando correctamente lo q no hace es devolver la fecha actual.....ya intente poniendole solo el now sin el select tampoco muestra tb utilice el current_date sin select pero nada.....
  #2 (permalink)  
Antiguo 16/05/2007, 10:53
 
Fecha de Ingreso: agosto-2006
Mensajes: 179
Antigüedad: 17 años, 9 meses
Puntos: 0
Re: como obtener fecha actual

current_date, tiene la fecha actual y now la fecha y hora actual, declare las variable sa las que le vas a asignar el valor de tipo varchar y no habra problema.


Saludos.
  #3 (permalink)  
Antiguo 16/05/2007, 14:06
 
Fecha de Ingreso: abril-2007
Mensajes: 27
Antigüedad: 17 años, 1 mes
Puntos: 0
Re: como obtener fecha actual

Cita:
Iniciado por rusinho Ver Mensaje
current_date, tiene la fecha actual y now la fecha y hora actual, declare las variable sa las que le vas a asignar el valor de tipo varchar y no habra problema.


Saludos.
lo hice de la sgte manera y me salio perfecto gracias....
declare la variable como me dijiste y le asigne a esa el valor del current_date y en el update le paso como parametro la variable declarada....

CREATE OR REPLACE FUNCTION REC_GER(NUM_PRE1 int,
OBS TEXT,
PASA BIT,
MAT_REV CHAR(3))
RETURNS void AS
$BODY$declare
fecha1 timestamp with time zone;
begin
IF PASA = '1' then
BEGIN
fecha1=current_date;
UPDATE PRESTAMO SET OBS_REV = OBS, ESTADO = 'RG', USR_REV = MAT_REV, FEC_REV =fecha1 WHERE NUM_PRE = NUM_PRE1;
END;
ELSE
BEGIN
UPDATE PRESTAMO SET OBS_REV = OBS , ESTADO = 'OG', USR_REV = MAT_REV, FEC_REV =fecha1 WHERE NUM_PRE = NUM_PRE1;
END;
end if;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION REC_GER(NUM_PRE1 int,
OBS TEXT,
PASA BIT,
MAT_REV CHAR(3)) OWNER TO postgres;
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:23.