problema con una funcion

From: amrod <amrodfull(at)gmail(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: problema con una funcion
Date: 2005-07-20 06:32:10
Message-ID: 3c2a0c9b05071923324ed3c4dc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

hola lista tengo el siguiente problema me piden solucionar el siguiente
problema :
Crear una función que sea capaz de leer la tabla de productos y retorne un
string formateado como Tabla HTML, debe incluir encabezados de campo, y al
final la cantidad de registros procesados en la función, como parámetro use
el campo por el cual será ordenada la tabla.
Puedo realisar el string pero el ordenamiento no me resulta ojala me puedan
dar alguna sugerensia para poder solucionar esto..
desde ya gracias..

CREATE OR REPLACE FUNCTION tabla (text) RETURNS text AS
'
declare
campo alias for $1;
total integer;
cadena_html text;
registro RECORD;
begin
cadena_html := ''<table>
'';
cadena_html := cadena_html || ''<tr>
'';
cadena_html := cadena_html || ''<td>id_producto</td>
'';
cadena_html := cadena_html || ''<td>id_unidad</td>
'';
cadena_html := cadena_html || ''<td>id_categoria</td>
'';
cadena_html := cadena_html || ''<td>nombre</td>
'';
cadena_html := cadena_html || ''<td>descripcion</td>
'';
cadena_html := cadena_html || ''<td>precio venta</td>
'';
cadena_html := cadena_html || ''<td>stock actual</td></tr>
'';

-- Cantidad de registros.

select into total count(*) from productos;

-- Obtener registro a registro.

for registro in select * from productos order by $1 loop --(e aqui el
probelma)
cadena_html :=
dice:
cadena_html || ''<tr>
'';
cadena_html := cadena_html || ''<td>'' || registro.id_producto || ''</td>'';
cadena_html := cadena_html || ''<td>'' || registro.id_unidad || ''</td>'';
cadena_html := cadena_html || ''<td>'' || registro.id_categoria ||
''</td>'';
cadena_html := cadena_html || ''<td>'' || registro.nombre || ''</td>'';
cadena_html := cadena_html || ''<td>'' || registro.descripcion || ''</td
dice:
>'';
cadena_html := cadena_html || ''<td>'' || registro.precio_venta ||
''</td>'';
cadena_html := cadena_html || ''<td>'' || registro.stock_actual ||
''</td>'';
cadena_html := cadena_html || ''</tr>
'';
end loop;
cadena_html := cadena_html || ''<tr><td>Cantidad registros: '' || total ||
''</td></tr>
'';
cadena_html := cadena_html || ''</table>
'';
return cadena_html;
end;
' LANGUAGE 'plpgsql'

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Oswaldo Hernández 2005-07-20 08:21:55 Re: problema con una funcion
Previous Message Erik De leon 2005-07-20 02:53:57 como usar el PERFORM y los CURSORES en postgresql