Página 1 de 1
consulta em campo LONG
Enviado: Seg, 04 Ago 2008 2:08 pm
por rmario36
Olá pessoal, boa tarde a todos.
Estou com um problemão e preciso do Help dos colegas.
Trabalho com BD Oracle 9i e preciso fazer uma consulta nuam tabela cujo campo que armazena históricos é do tipo "Long" e o PL/SQL não consegue me retorna o que preciso.
Segue exemplo da consulta
Selecionar tudo
select * from tabela t
where contains(t.historico,'eletrico') > 0
Por favor, alguém me ajude.
obrigado
Enviado: Seg, 04 Ago 2008 2:59 pm
por Trevisolli
Brother,
Esse "contains" é alguma função tua?
Você precisa recuperar o Lob apenas, ou, utilizar funções de extração como "Substr" etc nele?
consulta em campo long
Enviado: Ter, 05 Ago 2008 11:08 am
por rmario36
Trevisolli, bom dia.
Cara eu tentei utilizar a tal "Substr", mas não deu certo.
Será que você teria algum exemplo de como posso extrair uma palavra de um texto.
Obrigado.
Enviado: Ter, 05 Ago 2008 11:47 am
por Trevisolli
Brother, utilize o pacote
DBMS_LOB, que tem uma função chamada
SUBSTR.
Eu fiz um teste com o exemplo abaixo e deu certinho:
Selecionar tudo
SELECT DBMS_LOB.SUBSTR (SEU_CAMPO_CLOB, 41, 1)
FROM SUA_TABELA;
Nota: Utilizei na versão 10g do banco...
consulta em campo Long
Enviado: Ter, 05 Ago 2008 12:00 pm
por rmario36
Meu eu agradeço sua ajuda, mas novamente deu erro.
Primeiro que eu utilizo o Oracle 9i e agora esta dando a seguinte msg de erro: ilegal use of long datatype.
minha consulta ficou assim:
Selecionar tudo
SELECT DBMS_LOB.SUBSTR (historico, 41, 1)
FROM complementos;
Forte Abraço.
RMario
Enviado: Ter, 05 Ago 2008 12:48 pm
por Trevisolli
Brother,
Só 1 dica: Se não me falha a memória, os LONG's não existem após a 8i.
Você não poderia estar convertendo esses campos LONG para CLOB?
Selecionar tudo
You can use the TO_LOB function as part of an INSERT statement.
Given the following two tables:
CREATE TABLE long_table (n NUMBER, long_col LONG);
CREATE TABLE lob_table (n NUMBER, lob_col CLOB);
INSERT INTO lob_table
SELECT n, TO_LOB(long_col) FROM long_table;
Daí, com o
CLOB você consegue trabalhar com o pacote DMBS_LOB que mencionei no post anterior.
Qualquer dúvida, manda pra gente.
Consulta em campo "long"
Enviado: Seg, 11 Ago 2008 11:55 am
por rmario36
Trevisolli, meu brother, a coisa ta feia.
Não posso converter o campo da minha tabela de "long" para "Clob".
Não consegui realizar minha consulta ainda e não sei mais o que fazer.
Parece que inventaram este tipo de formato somente para encher o saco.
você tem alguma outra opção?
Abraço e obrigado por enquanto.
Roberto
Enviado: Seg, 11 Ago 2008 1:52 pm
por Trevisolli
Brother, realizei uns testes com o exemplo abaixo e funcionou aqui o
SUBSTR em um campo LONG.
Dê uma olhada:
01 - Criação da tabela com campo LONG:
02 - Substring de um retorno LONG em um VARCHAR2 de 32767.
Selecionar tudo
DECLARE
vteste LONG;
vteste_ret LONG;
vteste_sub VARCHAR2(32767);
BEGIN
FOR x IN 1..1000
LOOP
vteste := vteste || '123-';
END LOOP;
INSERT INTO teste1 VALUES (vteste);
COMMIT;
SELECT ds_long
INTO vteste_Ret
FROM teste1
WHERE ROWNUM <= 1;
vteste_sub := SUBSTR(vteste_ret,1,100);
dbms_output.put_line('Teste com substring: '||vteste_sub);
END;
Se não der certo ai, manda pra gente beleza?
Enviado: Seg, 18 Ago 2008 2:59 pm
por gokden
Campo Long
Enviado: Ter, 19 Ago 2008 7:32 am
por rmario36
Pessoal, valeu mesmo pelas dicas, obrigado.
Roberto
Olá
Enviado: Ter, 19 Ago 2008 9:34 am
por rmario36
Pessoal, bom dia.
Talvez eu não esteja sendo bem claro ao descrever minha dificuldade aos nobres colegas.
A minha demanda é a seguinte: eu tenho uma tabela na qual uma de suas colunas é do tipo "long".
Nesta bendita coluna do tipo "long", a qual recebe o nome de HISTORICO é armazenado um breve resumo do registro.
Meu chefe precisa saber num determinado período, quantas vezes ocorreu a inclusão de determinada palavra nesta tabela.
Assim, não basta eu saber quantas linhas eu tenho na tabela, o que eu preciso mesmo é SELECIONAR OS REGISTROS EM QUE APARECEM DETERMINADA PALAVRA.
Acredito que terá que ser uma consulta em que todas as linhas devem ser lidas e selecionadas.
Por favor, me ajudem...
Obrigado mais uma vez.
Abraços a todos .
Rmario36
Enviado: Ter, 19 Ago 2008 10:08 am
por dr_gori
Um cara chamado DAVID HUNT dá uma dica quanto a isso:
http://www.dba-oracle.com/t_select_long ... mn_sql.htm
Selecionar tudo
REM **********************************************************
REM Author: David Hunt
REM Date Created: July 18, 2007
REM Purpose: Creates function that returns contents of
REM PART_COMNT:COMNT_TXT. (a LONG field)
REM Warning: if the contents of COMNT_TXT exceed 32767 chrs, then
REM none of the data from that row's LONG RETURN;
REM an error message results.
REM **********************************************************
create or replace function Get_Comnt_txt
(RowID_of_Long in rowid)
return varchar2
is
Long_to_Varchar varchar(32767);
begin
select comnt_txt into Long_to_Varchar
from part_comnt
where rowid = rowid_of_long;
return long_to_varchar;
exception
when others then
return 'Error occurred on rowid: '||rowid_of_long;
end; /
select replace(get_Comnt_txt(rowid),chr(10),null)comnt_txt
from part_comnt;
COMNT_TXT
----------------------------------------------------------------
This is short text in a LONG column.
This is row 2; a <carriage return> is here ->This is row 2; a <carriage return> is here ->This is row 2; a <carriage return> is here ->
Selecionar tudo
create table rv_test (a number, b long)
/
insert into rv_test values (1, 'asdfjasraghavkjasdfdsafqafl;kasdfnbdsamnbfdasraghavasdfl')
/
insert into rv_test values (2, 'asdfjasdf;lkjadsflkjdasf;lkjasdflkjdsafl;kasdfnbdsamnbfdasraghavasdflkjasdf')
/
insert into rv_test values (3, & #39;asdfjasdf;lasdfa192387sfdsflkjdasf;lkjasdfdsafq3lkjdsafl;kasdfnbdsamnbfdasra
ghavasdflraghav')
/
commit
-- ************************
create or replace type rv_test_type as object(a number, b clob);
/
create or replace type rv_test_table as table of rv_test_type;
/
create or replace function rv_test_search(x varchar2)
return rv_test_table pipelined is
r rv_test_type;
begin
for f in (select * from rv_test) loop
if (f.b like x) then
r:= rv_test_type(f.a,f.b);
pipe row(r);
end if;
end loop;
end;
/
select a from table(rv_test_search('%raghav%'));
Algumas coisas importantes sobre LONG. (restrições).
he use of LONG values is subject to some
restrictions:
A table cannot contain more than one LONG column.
You cannot create an object type with a LONG attribute.
LONG columns cannot appear in integrity constraints (except for NULL and NOT
NULL constraints).
LONG columns cannot be indexed.
A stored function cannot return a LONG value.
Within a single SQL statement, all LONG columns, updated tables, and locked
tables must be located on the same database.
LONG columns cannot appear in certain parts of SQL statements:
WHERE clauses, GROUP BY clauses, ORDER BY clauses, or CONNECT BY clauses or
with the DISTINCT operator in SELECT statements
The UNIQUE operator of a SELECT statement
The column list of a CREATE CLUSTER statement
The CLUSTER clause of a CREATE MATERIALIZED VIEW statement
SQL functions (such as SUBSTR or INSTR)
Expressions or conditions
SELECT lists of queries containing GROUP BY clauses
SELECT lists of subqueries or queries combined by set operators
SELECT lists of CREATE TABLE ... AS SELECT statements
SELECT lists in subqueries in INSERT statements
Triggers can use the LONG datatype in the following manner:
A SQL statement within a trigger can insert data into a LONG column.
If data from a LONG column can be converted to a constrained datatype (such
as CHAR and VARCHAR2), a LONG column can be referenced in a SQL statement
within a trigger.
Variables in triggers cannot be declared using the LONG datatype.
:NEW and :OLD cannot be used with LONG columns.
However you can use the Oracle Call Interface functions to retrieve a
portion of a LONG value from the database.
O LONG ainda existe para manter compatibilidade apenas. Sempre que possível, use campos CLOB, BLOB, etc...
Re: consulta em campo LONG
Enviado: Qua, 30 Out 2019 3:26 pm
por GuGatto
Você pode criar uma função para converter o campo.
Selecionar tudo
CREATE OR REPLACE FUNCTION get_search_condition
(
p_owner all_constraints.owner%TYPE,
p_constraint_name all_constraints.constraint_name%TYPE
) RETURN VARCHAR2 IS
v_long LONG;
BEGIN
SELECT search_condition
INTO v_long
FROM all_constraints
WHERE constraint_name = p_constraint_name
AND owner = p_owner
AND constraint_type = 'C';
RETURN substr(v_long, 1, 32760);
END;
Depois usá-la na query:
Selecionar tudo
SELECT constraint_name,
get_search_condition(owner, constraint_name) AS search_condition
FROM all_constraints
WHERE owner = 'MYSCHEMA'
AND table_name = 'MYTABLENAME'
AND constraint_type = 'C'
AND get_search_condition(owner, constraint_name) = 'TEXT_SEARCH';