Como posso fazer isso?
exemplo
Select * from nnnn where nnnn.campo1 in (:txt1);
2501, 2502
vem:
Select * from nnnn where nnnn.campo1 in ('2501,2502');
eu queria saber como faço para vir:
Select * from nnnn where nnnn.campo1 in ('2501','2502');
Select * from nnnn where nnnn.campo1 in (:txt1);
2501, 2502
Select * from nnnn where nnnn.campo1 in ('2501,2502');
Select * from nnnn where nnnn.campo1 in ('2501','2502');
prompt especificação da PACK
create or replace package pack_teste_SQLdinamic is
procedure p_executar_sql_vilacidade(p_string_sql in varchar2,
p_nm_municipio in varchar2) ;
procedure p_obter_vilacidade_ibge (p_nm_municipio in varchar2 );
end pack_teste_SQLdinamic;
/
show err
/
prompt corpo da PACK
create or replace package body pack_teste_SQLdinamic is
procedure p_executar_sql_vilacidade(p_string_sql in varchar2,
p_nm_municipio in varchar2) is
-- variaveis
v_vilacidade varchar2(50);
v_cd_ibge number;
v_cursorid integer;
v_rows integer;
v_string_sql varchar2(2000);
--
begin
--
v_string_sql := 'select a.nm_vila_cidade, '||
'a.cd_ibge '||
'from tam_vilacidade a '||
'where a.nm_municipio = '||''''||p_nm_municipio||'''';
if p_string_sql is null then
raise_application_error(-20791, 'não foi passada nenhum select. Procedure abortada. ');
else
v_cursorid := dbms_sql.open_cursor;
dbms_sql.parse(v_cursorid, p_string_sql, dbms_sql.v7);
dbms_sql.define_column(v_cursorid, 1, v_vilacidade,50);
dbms_sql.define_column(v_cursorid, 2, v_cd_ibge);
v_rows := dbms_sql.execute(v_cursorid);
loop
--
if dbms_sql.fetch_rows(v_cursorid) = 0 then
exit;
end if;
dbms_sql.column_value(v_cursorid, 1, v_vilacidade);
dbms_sql.column_value(v_cursorid, 2, v_cd_ibge);
--
end loop;
dbms_sql.close_cursor(v_cursorid);
end if;
--
--exception when no_data_found then
--dbms_sql.close_cursor(v_cursorid);
end p_executar_sql_vilacidade;
--
-- ---------------------------------------------------------------------------------------------------------
--
procedure p_obter_vilacidade_ibge (p_nm_municipio in varchar2 ) is
--
v_string_sql varchar2(2000);
--
begin
v_string_sql := 'select a.nm_vila_cidade, '||
'a.cd_ibge '||
'from tam_vilacidade a '||
'where a.nm_municipio = '||''''||p_nm_municipio||'''';
--
p_executar_sql_vilacidade(v_string_sql,p_nm_municipio);
--
end p_obter_vilacidade_ibge;
end pack_teste_SQLdinamic;
/
show err
/
Select * from nnnn where nnnn.campo1
exists (select campo1
from tabela t
where t.campo1 =:parametro);
SELECT *
FROM dual
WHERE 1 IN (:x)
create or replace type tab_number as table of number;
create or replace
function f_virgulas_em_linhas
( p_string in varchar2
) return tab_number pipelined as
v_str varchar2(4000);
v_num number;
begin
v_str := p_string || ',';
while ( v_str is not null ) loop
v_num := to_number( substr( v_str, 1, instr( v_str, ',', 1 ) - 1 ) );
pipe row ( v_num );
v_str := substr( v_str, instr( v_str, ',', 1) + 1 );
end loop;
return;
end;
select column_value
from table( f_virgulas_em_linhas('4,8,15,16,23,42') )
;
COLUMN_VALUE
4
8
15
16
23
42
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante