Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Conexión con bases de datos

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 24-02-2011
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Poder: 23
gluglu Va por buen camino
Voy a cambiar la tabla de nombre para simplicarlo todo. Introducimos un único registro con un único valor = 1. Creamos el Stored Procedure.

Código Delphi [-]
CREATE TABLE PRUEBA(
    RANDOMNO DECIMAL(12,0)
);
 
INSERT INTO PRUEBA (RANDOMNO)
            VALUES (1);
COMMIT WORK;
 
SET TERM ^ ;
CREATE OR ALTER PROCEDURE NEW_PROCEDURE2 (
    in_random decimal(12,0))
returns (
    out_random decimal(12,0))
as
 declare variable aux_rand decimal(12,0);
 declare variable aux_rand2 decimal(12,0);
 declare variable aux_true integer;
begin
 
  AUX_TRUE  = 0;
 
  while (:"AUX_TRUE" = 0) do begin

    Select RANDOMNO from PRUEBA
      where RANDOMNO = :"IN_RANDOM"
      rows 1 into AUX_RAND;

    if (:"AUX_RAND" is null) then begin
      Leave;
    end
    else begin
      IN_RANDOM = IN_RANDOM + 1;
      if (IN_RANDOM > 200) then Leave;
    end

  end
 
  OUT_RANDOM = IN_RANDOM;
 
  suspend;
 
end
^
SET TERM ; ^

Y por último ejecutamos :
Código Delphi [-]
Select * from NEW_PROCEDURE2(1)
Esta sentencia me devuelve el valor 201.

Esta otra
Código Delphi [-]
Select * from NEW_PROCEDURE2(2)
me devuelve el valor 2.

Si pruebo con lo siguiente :
Código Delphi [-]
SET TERM ^ ;
CREATE OR ALTER PROCEDURE NEW_PROCEDURE2 (
    in_random decimal(12,0))
returns (
    out_random decimal(12,0))
as
 declare variable aux_rand decimal(12,0);
 declare variable aux_rand2 decimal(12,0);
 declare variable aux_true integer;
begin
 
  AUX_TRUE  = 0;
 
  while (:"AUX_TRUE" = 0) do begin

    Select RANDOMNO from PRUEBA
      where RANDOMNO = :"IN_RANDOM"
      rows 1 into AUX_RAND;

    if (:"AUX_RAND" is null) then begin
      Leave;
    end
    else begin
      IN_RANDOM = IN_RANDOM + 1;
      if (IN_RANDOM > 200) then Leave;
    end

  end
 
  OUT_RANDOM = AUX_RAND;
 
  suspend;
 
end
^
SET TERM ; ^
para ver qué valor queda en Aux_Rand, entonces

Código Delphi [-]
Select * from NEW_PROCEDURE2(1)
me devuelve el valor 1
y
Código Delphi [-]
Select * from NEW_PROCEDURE2(2)
me devuelve null.

P.D. La versión de Firebird es la 2.1
__________________
Piensa siempre en positivo !
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Stored Procedure !!! Ledian_Fdez C++ Builder 0 02-03-2010 14:01:29
Stored Procedure StartKill MySQL 2 27-08-2008 06:18:44
Ver los Stored Procedure tgsistemas SQL 0 06-04-2004 17:18:22
Stored Procedure tgsistemas SQL 1 27-02-2004 13:10:33
problema con stored procedure Markoz Firebird e Interbase 8 27-06-2003 13:46:31


La franja horaria es GMT +2. Ahora son las 12:18:00.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi