Home » SQL & PL/SQL » SQL & PL/SQL » Selecting specufuc column programmaticaly (Oracle 10g 10.2.0.3.0 on linux 64 bit)
Selecting specufuc column programmaticaly [message #349603] Mon, 22 September 2008 06:08 Go to next message
MIFI
Messages: 256
Registered: February 2008
Location: U.K.
Senior Member
Hi,
I want to query a table with specific column name, i need to select column name individually whereas my requirement is that i want to select column starting with 'T' programmitacaly.

Like i have a table abc with following column
id,
name,
Term1,
Term2,
Term3,
|
|
|
Term25
date

Re: Selecting specufuc column programmaticaly [message #349608 is a reply to message #349603] Mon, 22 September 2008 06:20 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
select term1, term2, ... from mytable

Regards
Michel
Re: Selecting specufuc column programmaticaly [message #349609 is a reply to message #349603] Mon, 22 September 2008 06:22 Go to previous messageGo to next message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Or would you rather base your code on USER_TAB_COLUMNS (where column name begins with a "T")?
Re: Selecting specufuc column programmaticaly [message #349617 is a reply to message #349609] Mon, 22 September 2008 06:41 Go to previous messageGo to next message
MIFI
Messages: 256
Registered: February 2008
Location: U.K.
Senior Member
yes but how do i convert record of column name into column name because user_tab_columns is giving me column name in result as record and i want to use those column name in my query.
Re: Selecting specufuc column programmaticaly [message #349620 is a reply to message #349617] Mon, 22 September 2008 07:09 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use dynamic query: build a string with your statement and use execute immediate or dbms_sql depending on your case.

Regards
Michel
Re: Selecting specufuc column programmaticaly [message #349673 is a reply to message #349617] Mon, 22 September 2008 10:56 Go to previous message
Alessandro Rossi
Messages: 166
Registered: September 2008
Location: Rome
Senior Member
MIFI wrote on Mon, 22 September 2008 13:41
yes but how do i convert record of column name into column name because user_tab_columns is giving me column name in result as record and i want to use those column name in my query.


Dynamic SQL is a process that requires multiple steps, because it acts at a deeper level of abstraction than static sql so you have to control all its phases to complete your job.

Read the documentation about DBMS_SQLto have a good understanding of it and make more specific questions to get a good feedback.

Bye Alessandro
Previous Topic: count of rows within 5 minute intervals
Next Topic: DBMS_SQL Describe columns from cursor
Goto Forum:
  


Current Time: Sun Dec 04 14:58:30 CST 2016

Total time taken to generate the page: 0.05727 seconds