consultation in the field LONG

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
Post Reply
rmario36
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 7
Joined: Tue, 29 Jul 2008 10:48 am
Location: São Paulo - SP
Olá Galera, bom dia.
Estou com problema e preciso de ajuda.
Preciso fazer a consultade uma palavra num campo do tipo "LONG" no Oracle 9i e me retorna uma msg de tabela não indexada.
Como resolver esse problema.
Valeu

Hello everyone, good afternoon everyone.
I have a problem and I need colleagues help.
Work with BD Oracle 9i and I need to make a consultation Nuam Table whose field that stores historical is the "Long" type and PL / SQL can not return to me.
Follow an example of the query

Select all

select * from tabela t 
where  contains(t.historico,'eletrico') > 0
Please, someone help me.

Thanks
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother,

This "Contains" is some of yours?
Do you need to recover the LOB only, or use extraction functions such as "substr" etc in it?
rmario36
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 7
Joined: Tue, 29 Jul 2008 10:48 am
Location: São Paulo - SP
Olá Galera, bom dia.
Estou com problema e preciso de ajuda.
Preciso fazer a consultade uma palavra num campo do tipo "LONG" no Oracle 9i e me retorna uma msg de tabela não indexada.
Como resolver esse problema.
Valeu

Trevisolli, good morning.
Face I tried to use such a "substr", but it did not work.
Would you have any example of how I can extract a word from a text.
Thanks.
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother, use the dbms_lob package, which has a function called subr .

I did a test with the example below and gave right:

Select all

 
SELECT DBMS_LOB.SUBSTR (SEU_CAMPO_CLOB, 41, 1) 
  FROM SUA_TABELA; 
Note: I used in version 10g from the bank...
rmario36
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 7
Joined: Tue, 29 Jul 2008 10:48 am
Location: São Paulo - SP
Olá Galera, bom dia.
Estou com problema e preciso de ajuda.
Preciso fazer a consultade uma palavra num campo do tipo "LONG" no Oracle 9i e me retorna uma msg de tabela não indexada.
Como resolver esse problema.
Valeu

My I thank you for your help, but again gave mistake.
First I use Oracle 9i and is now giving the following error MSG: Illegal Use of Long Datatype.

My consultation was like this:

Select all

SELECT DBMS_LOB.SUBSTR (historico, 41, 1)  
  FROM complementos;  
strong embrace.

Rmario
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother,

Only 1 tip: If no memory fail, the Long's do not exist after 8i.
You could not be converting these LONG fields to CLOB?

Select all

 
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; 
 

Hence, with the clob you can work with the DMBS_LOB package that I mentioned in the previous post.

Any questions, send us.
rmario36
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 7
Joined: Tue, 29 Jul 2008 10:48 am
Location: São Paulo - SP
Olá Galera, bom dia.
Estou com problema e preciso de ajuda.
Preciso fazer a consultade uma palavra num campo do tipo "LONG" no Oracle 9i e me retorna uma msg de tabela não indexada.
Como resolver esse problema.
Valeu

Trevisolli, my brother, the ugly thing.
I can not convert the field from my "long" table to "clob".
I could not accomplish my query yet and I do not know what else to do.
looks that they invented this type of format only to fill the bag.
Do you have any other option?
Embrace and thank you for now.
Roberto
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother, I made tests with the example below and worked here substr in a long field.

Take a look:
01 - Creating the table with LONG field:

Select all

 
CREATE TABLE teste1 (ds_long LONG); 
02 - Substring a long return In a varchar2 of 32767.

Select all

 
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; 
If it does not work there, send us beleza?
gokden
Rank: DBA Pleno
Rank: DBA Pleno
Posts: 264
Joined: Sun, 19 Aug 2007 8:18 pm
Location: Ribeirão Preto - SP
Lucas de Souza

OCA Developer
Analista de sistemas

or intact type:

Select all

set long 2000
= D
rmario36
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 7
Joined: Tue, 29 Jul 2008 10:48 am
Location: São Paulo - SP
Olá Galera, bom dia.
Estou com problema e preciso de ajuda.
Preciso fazer a consultade uma palavra num campo do tipo "LONG" no Oracle 9i e me retorna uma msg de tabela não indexada.
Como resolver esse problema.
Valeu

Guys, thanks even for the tips, thank you.
Roberto
rmario36
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 7
Joined: Tue, 29 Jul 2008 10:48 am
Location: São Paulo - SP
Olá Galera, bom dia.
Estou com problema e preciso de ajuda.
Preciso fazer a consultade uma palavra num campo do tipo "LONG" no Oracle 9i e me retorna uma msg de tabela não indexada.
Como resolver esse problema.
Valeu

Guys, good morning.
Maybe I'm not being clear when describing my difficulty at nobles colleagues.
My demand is as follows: I have a table in which one of your columns is the "long" type.
In this blessed "Long" column, which receives the historic name is stored a brief summary of the registry.
My boss needs to know in a certain period, how often the inclusion of a certain word in this table occurred.
So, do not just know how many lines I have on the table, which I really need is to select the records in which a particular word appear.
I believe it will have to be an appointment where all lines should be read and selected.
Please help me ...
Thanks again.
Hugs to all.

Rmario36
User avatar
dr_gori
Moderador
Moderador
Posts: 5026
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

A guy named David Hunt gives a tip about this: http://www.dba-oracle.com/t_select_long ... mn_sql.htm

Select all

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 -> 
 

Select all

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%'));
Some important things About Long. (restrictions).
He Use Long Values ??Is Subject to Same
Restrictions:

The 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 (Exceed for NULL AND NOT
NULL CONFRAINTS).
Long columns cannot be indexed.
The STORED FUNCTION CANNOT RETURN A LONG VALUE.
Within 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 Substr or instr)
Expressions or Conditions
Select Lists of Queries Containing Group by Clauses
Select Lists Of Subcuries or Queries Combined By Set Operators
Select Lists of CREATE TABLE ... The Select Statements
Select Lists in Insert Statements

Triggers Can Use The Long Datatype in the Following Manner:
SQL Statement Within A Trigger Can Insert Data Into Long Column.
IF Data from A Long Column Can Be Converted to Constrained Datatype (Such
The Char and Varchar2), the Long Column Can Be Referenced In A SQL Statement
Within to 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 Value from the database.
Long still exists for Keep compatibility only. Whenever possible, use Clob fields, blob, etc ...
GuGatto
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 2
Joined: Wed, 30 Oct 2019 3:07 pm
Location: Campinas/SP

You can create a function to convert the field.

Select all

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;
then use it at Query:

Select all

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';
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest