Home » SQL & PL/SQL » SQL & PL/SQL » Capitalization of multiple words in one query (Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)
Capitalization of multiple words in one query [message #629551] Wed, 10 December 2014 11:20 Go to next message
Malkav
Messages: 4
Registered: December 2014
Location: Barcelona
Junior Member
Hi to everyone, thanks for reading and sorry for my english.
I must capitalize a list of words in diferent entries of the same table.
I have a query that does it, but just with one word at a time.
I want to know if there is a way to capitalize the first character of all the words in a list for all the entries.

This is what I have:

SELECT rre_reference_id AS reference_id, rre_ref_title AS reference_title, REPLACE(rre_ref_title, 'alzheimer', INITCAP('alzheimer'))
FROM adminoltp.ref_references
WHERE rre_ref_title LIKE '%alzheimer%';


I can do that with all the words, not just "alzheimer"; but I don't know how to do it with one query.

Thank you for your time, Smile

Carlos.


Edit: It's a select but I will change it to an update.

[Updated on: Wed, 10 December 2014 11:21]

Report message to a moderator

Re: Capitalization of multiple words in one query [message #629553 is a reply to message #629551] Wed, 10 December 2014 12:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
With any SQL or PL/SQL question, please, Post a working Test case: create statements for all objects so that we will be able work with your table and data.

Re: Capitalization of multiple words in one query [message #629575 is a reply to message #629553] Thu, 11 December 2014 02:49 Go to previous messageGo to next message
Malkav
Messages: 4
Registered: December 2014
Location: Barcelona
Junior Member
Hello Michel, thank you for your answer.
I don't know what more is needed. I want to update a column, capitalizing the first character of the words that are in a list.
Table is "ref_references", and contains one column called "rre_ref_title" that is VARCHAR2(600) (the title of the reference). If that column contains words like "alzheimer", "parkinson", "hepatitis"; I should update just that words to "Alzheimer", "Parkinson", "Hepatitis".

That query can update one word at a time. But is there a way to replace a list of words in one query?

UPDATE adminoltp.ref_references
SET rre_ref_title = REPLACE(rre_ref_title, 'alzheimer', INITCAP('alzheimer'))
WHERE rre_ref_title LIKE '%alzheimer%';


If you need any info, please ask.

Thank you.
Re: Capitalization of multiple words in one query [message #629576 is a reply to message #629575] Thu, 11 December 2014 02:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
I don't know what more is needed.


What is explained in the link and I repeat in my post : CREATE TABLE statement for your tables and INSERT statement for an example of data.

"Table is ": we have not and so we can't work on and test some solutions.

Re: Capitalization of multiple words in one query [message #629577 is a reply to message #629576] Thu, 11 December 2014 03:42 Go to previous messageGo to next message
Malkav
Messages: 4
Registered: December 2014
Location: Barcelona
Junior Member
To create the table:

CREATE TABLE REF_REFERENCES
( RRE_REFERENCE_ID NUMBER(8) NOT NULL,
  RRE_REFERENCE_TITLE VARCHAR2(600)
);


To fill the table:


INSERT INTO REF_REFERENCES (RRE_REFERENCE_ID, RRE_REFERENCE_TITLE)
VALUES (1, 'Waldheim brain drugs for alzheimer and alcoholism');


INSERT INTO REF_REFERENCES (RRE_REFERENCE_ID, RRE_REFERENCE_TITLE)
VALUES (2, 'DRD4 genotype and activity level predict alzheimers in the oldest-old');


INSERT INTO REF_REFERENCES (RRE_REFERENCE_ID, RRE_REFERENCE_TITLE)
VALUES (3, 'Chiron reports cloning of hepatitis C virus protein');



Expected behaviour:

Update first letter of the words hepatitis, alzheimer, crohn, etc. in one query.

Thank you.

[Updated on: Thu, 11 December 2014 03:43]

Report message to a moderator

Re: Capitalization of multiple words in one query [message #629578 is a reply to message #629577] Thu, 11 December 2014 03:57 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Update first letter of the words hepatitis, alzheimer, crohn, etc.


Where "etc." is defined? Smile

Re: Capitalization of multiple words in one query [message #629579 is a reply to message #629578] Thu, 11 December 2014 04:00 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Nested REPLACE might do the job, such as
select  
  replace(replace(replace(rre_reference_title, 'alzheimer', 'Alzheimer'), 
                                               'hepatitis', 'Hepatitis'),
                                               'genotype' , 'Genotype' )
from ref_references
Re: Capitalization of multiple words in one query [message #629581 is a reply to message #629579] Thu, 11 December 2014 04:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

But if there are other values? And if they are not a fixed list? So my previous question.

Re: Capitalization of multiple words in one query [message #629586 is a reply to message #629581] Thu, 11 December 2014 05:31 Go to previous message
Malkav
Messages: 4
Registered: December 2014
Location: Barcelona
Junior Member
The list is longer but it's a fixed list.
Thank you for the help LittleFoot, I will update you with the results Smile
Previous Topic: Query Rewrite and Self-Joins
Next Topic: Maker-Checker in Oracle
Goto Forum:
  


Current Time: Wed Apr 17 19:33:55 CDT 2024