Search value in the field after a character

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
Post Reply
thatifc
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 15
Joined: Thu, 03 May 2007 5:35 pm
Location: São Paulo - SP

Good evening!
I need to get a data, but in the field I have other recorded information, and what "separates" this information is the comma. I want to pick up only what appears after the comma.
Thus:
'Example, test'

I want only the 'test' value ... The content until the virgulum is variable, so I can not use The substr.

Please, how could you do it?
: Roll:

Thank you!
thatifc
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 15
Joined: Thu, 03 May 2007 5:35 pm
Location: São Paulo - SP

Ah! One more thing:
I can not use function, because I'm creating an ALERT (in ERP) and there only accepts the simple select ... I need to do the "treatment" in the same field.
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

Thati, try this code:

Select all

 
DECLARE 
  v_string VARCHAR2(50) := 'Paulo;Trevisolli';  
BEGIN 
  dbms_output.put_line(' Depois do ponto e virgula : ' || SUBSTR(v_string,INSTR(v_string,';')+1,11)); 
END; 
Whatever it sends there.
Hahu
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 147
Joined: Thu, 16 Mar 2006 11:26 am
Location: São Paulo
O mundo gira muito!!

Speak thatifc,
Good afternoon,

So, make a selection of the column you need !!

Create a spool C: \ test.txt on SQLPlus and then open in Excel, separating by virgins from the Tools menu, importing external data, Deee you put the tab by ",": LOL:

any things, post here in the forum!

abs hahu
thatifc
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 15
Joined: Thu, 03 May 2007 5:35 pm
Location: São Paulo - SP

Trevisolli and Hahu,

muito Thanks for the return !!
Here is the way I found to solve this pendenga:

Select all

 
Select Substr('Exemplo,Teste', Instr('Exemplo,Teste', ',')+1) 
  From Dual 
TKS !!
Thati

: Wink:
ironijunior
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 9
Joined: Wed, 06 Jun 2012 4:48 pm

I have a very similar question:

In your case you searched for the second item of the "list", but if I had more than two items and wanted to seek only the second? Because the way you did it will return everything after the second.

Select all

Select Substr('Exemplo,Teste, Exemplo2', Instr('Exemplo,Teste,Exemplo2', ',')+1) 
  From Dual
This will return: "Test, Example2"

How could I do to seek only the test?
User avatar
adrianoturbo
Moderador
Moderador
Posts: 393
Joined: Thu, 20 Mar 2008 4:09 pm
Location: Brasília
Adriano Alves
---Para cada problema dificil existe uma solução simples.----

Ironijunior, just adjust the string incrementator, follow the example:

Select all

 
SQL> SELECT SUBSTR('Exemplo,Teste,Exemplo2',+9,5) FROM DUAL; 
 
SUBST 
----- 
Teste 
 
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests