Обсуждение: dinamic sql

Поиск
Список
Период
Сортировка

dinamic sql

От
"Manso Gomez, Ramon"
Дата:
Hi

I need to write a Postgres function which executes a cursor. Query of this cursor however is created on the basis of parameters passed by user.


if(user_Input = 'a')
l_query := l_query||a_from_clause ||'where ename in '||user_Input
else
if(user_Input = 'b')
l_query := l_query||b_from_clause||'where ename in '||user_Input

OPEN csr FOR l_query;


How do we do it is postgres. My problem I know how to pass parameters like "ename=parameter", but If the SQL sentence is  ename in (parameters). It does not work.

Thanx in Advance.

Re: dinamic sql

От
"Jaime Casanova"
Дата:
On 8/29/06, Manso Gomez, Ramon <rmgomez@indra.es> wrote:
>
> if(user_Input = 'a')
> l_query := l_query||a_from_clause ||'where ename in '||user_Input
> else
> if(user_Input = 'b')
> l_query := l_query||b_from_clause||'where ename in '||user_Input
>
> OPEN csr FOR l_query;
>

l_query := l_query || a_from_clause                             || 'where ename in (' ||
quote_literal(user_input) || ')'

-- 
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."                                      Richard Cook