Return column name in lowcase
Hi,
how can I make Oracle ODBC Driver (8.01.72.00) returning column name in small letters ?
Thanks for any help.
Pardon my stupidity, but I'm still a little confused. Perhaps it's too early in the morning...
If you create a table foo in Oracle, i.e.
create table foo (
col1 varchar2,
col2 integer )
col1 & col2 are stored as uppercase in the database, although queries against the table are case-insensitive. For instance
select col1 from foo;
select COL1 from foo;
select cOl1 from foo;
all return the same thing
If you instead create a table
create table foo (
"col1" varchar2,
"col2" integer )
col1 & col2 are stored as case-sensitive column names, in this case lower case. Because the column names are case-sensitive,
the SQL statement
select "col1" from foo;
will return the correct data, while
select col1 from foo;
will cause an error.
Is this helpful to you? I guess I'm not sure where it is that you're generating or gathering column names, so I'm not sure how much control you have.
If you're gathering column names by making calls to catalog functions like SQLTables, I assume you can simply use the appropriate LOWER() function call to create lowercase column names.
If you can explain in a little more detail, preferrably with reference to the particular ODBC calls you're making, I might be able to help a little more.
Justin
Similar Messages
-
Is it possible to return column names?
Hi!
Is it possible to return column names of a select statement?
Let's say I have table with the following columns:
Col1
COl2
Col3
And I have a select statement like this:
Select * from XX
Is it then possible either through SQL or PL/SQL to return the column names?
Br
Casper ThraneIf you are looking at column names for a particular table,
then you can query aganist the sys.User_Tab_Columns.
here is the piece of code.
SELECT Column_Name
FROM Sys.User_Tab_Columns
WHERE Table_Name = 'TABLENAME';
Remember TABLENAME is the name of the table in CAPITAL letters.
You can use this in SQL or PL/SQL code.
You can also use the ALL_Tab_Columns but then you have add
another AND condition, because, the there may be a same table name for different users. so one has to use the owner Column in your query.
SELECT Column_Name
FROM All_Tab_Columns
WHERE Table_NAME = 'TABLENAME'
AND OWNER = 'TABLE_DESIRED_OWNER'; -
How to return column name in some table?
Hi All,
I know :system.cursor_value which returns the value of the current text item in the form.
But Is there a way to return the column name and its value in some table?
Note: I'm using Oracle DB 10g
Thank youDid you read the original post? [...] You don't understand what I want and you don't say antthing useful for my goal!
This is the SQL and PL/SQL forum. You need the Mind-Readers' forum down the hall.
First you asked "Is there a way to return the column name and its value in some table?", and were told you can get the former from the data dictionary (you can get the latter from the table itself).
Then you say you "want to create a trigger on a table", which tells us nothing about your problem.
Finally you say "but suppose the table contains 50 columns then I have to write 50 columns names three times", which is essentially true - but the process can be automated. What you (probably) need to do is write queries based on the data dictionary tables that generates the PL/SQL that you ultimately put in your triggger - you then use that output to build the trigger(s).
I don't think there's any way, at run time, to generically fish out all the columns of a table with their :new and :old values - you have to write (or auto-generate) specific code for each table. -
Query to return column name of first NULL column?
I have a table with 40 columns but only the first n have non-null values. Is there a way to pull the name of the first non-null column? I have tried using CASE but I run into nesting too deeply problems (apparently you can only nest to 10 levels).
Thank you.
Kevin
Kevin BurtonOr, you could try something like this:
-- This is just for testing
DROP TABLE #test
CREATE TABLE #Test
(ID INTEGER
,n1 INTEGER
,n2 INTEGER
,n3 INTEGER
,n4 INTEGER
,n5 INTEGER
,n6 INTEGER
,n7 INTEGER
,n8 INTEGER
,n9 INTEGER
INSERT INTO #Test
VALUES (1,256,365,4000,0,NULL,NULL,NULL,NULL,NULL)
SELECT *
FROM #Test
-- THIS IS THE IMPORTANT PIECE
SELECT ISNULL(LEN(LEFT(n1,1)),0)
+ ISNULL(LEN(LEFT(n2,1)),0)
+ ISNULL(LEN(LEFT(n3,1)),0)
+ ISNULL(LEN(LEFT(n4,1)),0)
+ ISNULL(LEN(LEFT(n5,1)),0)
+ ISNULL(LEN(LEFT(n6,1)),0)
+ ISNULL(LEN(LEFT(n7,1)),0)
+ ISNULL(LEN(LEFT(n8,1)),0)
+ ISNULL(LEN(LEFT(n9,1)),0)
FROM #Test
The LEFT(x,1) will always either give you a LEN of 1, or a NULL. Add 'em up. Try it.
Then use the Ordinal_Position from the Information Schema to get the name of the column (if that is what you need)
Duncan Davenport -
Return the column names for which the row values are not null.
Hi i m a new guy to db admin, and i need a sql script which should return column names of the particular table. and the returned column should have value (fyi - if the column has null value column name should not come in the sql o/p).
Exmple:
table name - A
s.no name mark status fee
1 aa 45 p null
2 bb 30 null paid
3 cc 35 p paid
fyi -1) if i give the table name(A) and s.no (2) the o/p should be -- name,mark.
2) if i give the tablename(A) and s.no (1) the o/p should be --- name,mark,status.
Thanks
Krishna.
Edited by: user13294228 on Jun 14, 2010 10:54 PMBTW,
The previous solution is for all values of the column, if you want a specific row, you can add it in where clause.
I mean in your example, it you look like:
SET serveroutput on;
DECLARE
l_cnt NUMBER;
l_str VARCHAR2 (255) := '';
l_table_name VARCHAR2 (255) := 'YOUR_TABLE_NAME';
l_col_cond VARCHAR2 (255) := 'S_NO';
l_val NUMBER := 1;
CURSOR c_col
IS
SELECT column_name
FROM user_tab_columns
WHERE table_name = l_table_name;
BEGIN
FOR i IN c_col
LOOP
EXECUTE IMMEDIATE 'SELECT COUNT ('
|| i.column_name
|| ') FROM '
|| l_table_name
|| ' WHERE '
|| l_col_cond
|| ' = '
|| l_val
INTO l_cnt;
l_str := l_str || CASE
WHEN l_cnt = 0
THEN ''
ELSE i.column_name
END || ',';
END LOOP;
l_str := SUBSTR (l_str, 1, LENGTH (l_str) - 1);
DBMS_OUTPUT.put_line (l_str);
END;Saad,
Edited by: S.Nayef on Jun 15, 2010 11:54 AM -
How to pass column name in slect statement in query
hi,
i want to make a report where in query select statement using variable as a column name. but its not working plz guide me how can i do this.
i have created a function which return column name through variable & that variable i want to to use in select statement
select :m1 from table1;
regardsHi,
Create a user parameter (say P_field), and assign a valid field name as initial value (say NAME), And In the Query, write
SELECT CODE, &P_field FN_FIELD FROM <table_name> WHERE <condition>And in the BEFORE PARAMETER FORM Trigger under the Report Triggers, write,
function BeforePForm return boolean is
begin
:P_field := <your_function_call>;
return (TRUE);
end;And use that FN_FIELD field in the report.
Hope this will clear your issue.
Regards,
Manu. -
ResultSetMetaData.getColumnLabel(int coluN) gives column name with quote
I am using ojdbc14.jar for "Oracle Database 10g Enterprise Edition Release 10.2.0.3.0". My query is "Select 'column name' from dual". When i get column name using ResultSetMetaData.getColumnLabel(int coluN) it return column name including single quotes ie: for the above query result is 'columname'. Ideally it should not return ' (single quote).
Why do this happening?You will have that even when you run with sqlplus.
=
Ashok -
Invalid column name - fixed by inserting a carriage return - Why?
I'm writing some JSP pages and am executing a statement that retrieves values from three tables.
When executing the statement I receive the error
java.sql.SQLException: Invalid column name
I just want to state here that ALL the column names are definitely correct. I attempted to isolate the problem using my SQL*Plus Interface.
When copying and pasting the SQL that was used (I put the SQL statement into the HTML to allow me to do this) into SQL*Plus it also come up with the error. I found that if I broke up the statement it would run. Specifically if I placed a carriage return (by hitting enter) prior to the 'A' of the AND operator and then copied and pasted into SQL*Plus it would work!
I thought the problem was related to bad syntax in the outer join operator. But removal of the outer join operator and making it a EQUI JOIN situation still gave the same results. I tried the use of brackets to 'help' the DB engine figure it out - silly I know, but it didn't work anyway :(
I've tried this out on UNIX in SQL*Plus where the query was on one line and it worked fine. I've tried it on Oracle 8.1.5 SQL*Plus & Oracle 8.1.7 SQL*Plus on Win2000 and WinNT and no go.
It has also been tested on an Oracle 7.3.4 DB and no go either.
Remember I'm only using SQL*Plus to find out why it is not working - I'm actually attempting to execute this via JDBC (classes12.zip Oracle9 version) in my JavaBean. I can't place a carriage return to 'fix' the problem, and I'm assuming that I shouldn't either.
I've pasted the SQL below (both non-working and working versions). I was going to paste the output of DESC on the associated tables should you too would rule out a mispelled column name, but I didn't want to put anyone off with a long post.
If you can provide any advice I would be very appreciative.
Darren James
Show Me Technology
SQL> SELECT UNIT.Asset_Number,Model,PERSON.Novell_User_Name FROM
UNIT, UNIT_USERS, PERSON
2 WHERE UNIT.Hardware_Reference_Number =
UNIT_USERS.Hardware_Reference_Number(+) AND UNIT_USERS
.Novell_User_Name = PERSON.Novell_User_Name (+) ORDER BY Make,
Model, Asset_Number,Serial_Number,
UNIT.Hardware_Reference_Number,Unit_Type,PERSON.Last_Name,PERSON.Fi
rst_Name,PERSON.Novell_User_Name;
3 /
WHERE UNIT.Hardware_Reference_Number =
UNIT_USERS.Hardware_Reference_Number(+) AND UNIT_USERS.Novel
ERROR at line 2:
ORA-00904: invalid column name
REM -- Using the one with an return prior to the AND
SQL> SELECT UNIT.Asset_Number,Model,PERSON.Novell_User_Name FROM
UNIT, UNIT_USERS, PERSON
2 WHERE UNIT.Hardware_Reference_Number =
UNIT_USERS.Hardware_Reference_Number(+)
3 AND UNIT_USERS.Novell_User_Name = PERSON.Novell_User_Name
(+) ORDER BY Make, Model,
4 Asset_Number,Serial_Number,
5
UNIT.Hardware_Reference_Number,Unit_Type,PERSON.Last_Name,PERSON.Fi
rst_Name,PERSON.Novell_User_
Name;
ASSET_NUMBER
MODEL
NOVELL_USE
10023445
desktop raider
tabisho
10023445
desktop raider
pjblee
100349864
VEi8
SQL>Ok. I feel ashamed that the answer was so simple and not the
problem I thought it was. But in the interests of perhaps
preventing someone else doing the same silly thing....
The error was caused by using a wrong name when 'getting' the
values int the return ResultSet object. (eg using getString
("s.Some_Name") when it should have been getString
("s.Another_Name").
Interestingly the error did occur in one of our SQL*Plus
versions. Why we still are not sure, but since this was a silly
error on my part, I'm sure a similarly silly reason will be the
cause there two.
I appreciate those who responded though. It is a great resource.
Darren James
I'm just guessing here, but could it be some sort of a size thing? Could it be that, if you don't break up line 2, somehow
it gets truncated or wrapped at an inappropriate place? To test
this theory, you might try putting the carriage return in front
of the ORDER BY, instead of in front of the AND, and see if it
has the same effect. If you do get it figured out, please
satisfy our curiosity and let us know. -
Column exist but ResultSet.getString(String) return invalid column name
With oracle 7 db the ResultSet.getString(String) works fine but after the upgrade to oracle 8 db it return invalid column name. ResultSet.getString(int) method works fine.
Is this a bug in the driver?
Thanks
-RedaYes I'm 100 % sure that the columns exist.
-RedaWell then maybe it's a bug in the Oracle driver. Lord knows it wouldn't be the first time that's happened. -
Using Column Name returned by function in SELECT statement
Hi
Output from my function (RETURN data type is VARCHAR2) is column name. I want to use it directly in my SELECT statement. Below is simplified example of this:
--- Function
CREATE OR REPLACE FUNCTION simple RETURN varchar2 IS
BEGIN
RETURN ‘my_column’;
END simple;
--- Select
SELECT simple FROM my_table;
This does not work. It seems that output from function is passed in quotation i.e.
SELECT ‘my_column’ FROM my_table;
So the output from SELECT is a list of rows populated with values my_table:
COLUMN simple
ROW1 my_column
ROW2 my_column
ROW3 my_column
Can please someone help me with this?I'm not sure I got you right.
In standard SQL everything must be known at compile time. If not dynamic SQL is required, but is a costly operation (usually requires parsing before each execution) so it should better not be used when standard SQL can do it.
I provided a design time example where a function returns the column name from the given the table name and column id for a varchar2 column data type to make things simple. Then a query string is constructed and executed dynymically to return all column values of the chosen table_name.column_name.
SELECT simple FROM my_tableAt compile time the simple function return value is unknown (any varchar2 value would do) you already find out you get the (same) return value (i.e column name) for each table row => dynamic SQL needed to get the column values
The purpose of function would be to rename all columns for provided table.The table name would be provided, right? If yes => dynamic SQL
What is the function supposed to return the column name (where would the new name come from?), the column alias (which table column would be renamed to the new name?)
The user could use the new_column name as the column alias name submitting the query.
Is it possible to do this?Maybe () using a pipelined function (different data types - number,date, ... not cosidered yet) but your simple query;
<tt>SELECT simple FROM my_table</tt>
might look like:
<tt>select my_column_value new_column_name from table(get_column_value(table_name,column_name))</tt>
Sorry, no Database at hand to provide a specific example.
Regards
Etbin -
Need to return dynamic column names for a function returning nested table
I am having a pl/sql function which is returning a nested table.
For this i have defined an object which is having 4 attributes- 1 number type, 3 varchar2 type -p1,p2,p3.
My function is taking input parameter v1,v2,v3 all of varchar2 type.Inside the function body,i am using these (v1,v2,v3) to filter data from an sql query and i am also
using pivot function in this sql query.
At the end my function is returning the object as defined in the starting .
When i am excuting this function,thru select statement :
select * from table(f1_test('A','B','C'));
i am geting p1,p2,p3 as column name ,which are names used when i had defined object type.Instead i want column name to be dynamic (wotever i am passing in function as
parameter while executing the function ,here A,B,C)
Please help me in geting column names dynamic as passed in input parameter (i.e A,B,C for this case )
Sample code for the problem:
create or replace TYPE obj1 AS OBJECT
( id number(5,0)
,p1 varchar2(10),
,p2 varchar2(10)
,p3 varchar2(10)
create or replace TYPE tt1 AS TABLE OF OBJ1;
create or replace
function f1_test (v1 varchar2,v2 varchar2,v3 varchar2)
return tt1 as
v_return tt1 ;
v_str varchar2(30000);
begin
v_str:='
select
cast(
multiset(
select * from
select
aa.report_id
,cc.name
,e.amount
from
aa,cc,e
where
<join conditions>
and cc.name in ('''||v1||''','''||v2||''','''||v3||''')
pivot (sum (amount) for name in ('''||v1||''' as '||v1||','''||v2||''' as '||v2||','''||v3||''' as '||v3||'))
as tt1)
from
dual';
dbms_output.put_line(v_str);
execute immediate v_str
into
v_return ;
return v_return;
end;
Edited by: 845831 on 20 Mar, 2011 12:15 PMselect id,p1 A,p2 B,p3 C from table(f1_test('A','B','C'));
drop function f1_test;
drop type tt1;
drop type obj1;
create or replace TYPE obj1 AS OBJECT
( id number(5,0)
,p1 varchar2(10)
,p2 varchar2(10)
,p3 varchar2(10)
create or replace TYPE tt1 AS TABLE OF OBJ1;
CREATE OR REPLACE
FUNCTION f1_test(
v1 VARCHAR2,
v2 VARCHAR2,
v3 VARCHAR2)
RETURN tt1
AS
v_return tt1 ;
v_str VARCHAR2(30000);
BEGIN
v_str:='select cast(multiset(select 1,''20'',''30'',''40'' from dual) as tt1) from dual';
dbms_output.put_line(v_str);
EXECUTE immediate v_str INTO v_return ;
RETURN v_return;
END;
/ -
Need a Query that Returns both Column Name with Column Data
Hi,
Hope someone can assist quite quickly. I'm after a query that will return me both column name together with column data, i.e
Table: APP_INFO
COL1 - currently has the value of 10
COL2 - currently has the value of 'HELLO'
COL3 - currently has the value of 'QWERTY'
COL4 - currently has the value of 2000Query I'm after is to return the following result set: [actual column name, actual column data]
COL1,10
COL2,'HELLO',
COL3,'QWERTY'
COL4,2000
Any help would be much appreciated.
Thanks.
Tony.Like this ?
SQL> select empno, ename, deptno from emp where deptno = 10;
EMPNO ENAME DEPTNO
7782 CLARK 10
7839 KING 10
7934 MILLER 10
SQL> select decode(t.id,1,'EMPNO',2,'ENAME',3,'DEPTNO') COLNAME,
2 decode(t.id,1,to_char(empno),2,ename,3,deptno)
3 from (select emp.*, rownum rn from emp
4 where deptno = 10) emp, (select rownum id from dict where rownum <=3) t
5 order by emp.rn, t.id
6 /
COLNAM DECODE(T.ID,1,TO_CHAR(EMPNO),2,ENAME,3,D
EMPNO 7782
ENAME CLARK
DEPTNO 10
EMPNO 7839
ENAME KING
DEPTNO 10
EMPNO 7934
ENAME MILLER
DEPTNO 10
9 rows selected.Rgds. -
How to write a Query a table and the return result is the column name
Hi All
Pls advise how to write a query whereas the return result is the
column name.
I know there is describe <table_name>;
Is there any other ways?
Pls advise
Tj
Edited by: user600866 on Oct 14, 2008 12:13 AMData Dictionary table user_tab_columns has all the column names. You can query that and get what ever you want.
To get the column list of a table just query
select *
from user_tab_columns
where table_name = <your_table>Edited by: Karthick_Arp on Oct 14, 2008 12:18 AM -
Incorrect column names returned using OCIDescribeAny
I am trying to retrieve column names using OCIDescribeAny and OCIAttrGet api calls.
The column names and the lengths of the column names returned by OCIAttrGet calls are usually correct.
Except when the length of column names are divisible by 4, an extra tab is padded at the end of the returned string by OCIAttrGet.
The length returned by the call is fine.
Example 1.
Column Name:
CITY
Results Returned by OCIAttrGet:
column name: CITY\t
column length: 4
Example 2.
Column Name:
PHONE_NUMBER
Results Returned by OCIAttrGet:
column name: PHONE_NUMBER\t
column length: 12
Does anyone has experience with this?
Edited by: simon780 on Mar 13, 2010 2:48 PM
Edited by: simon780 on Mar 13, 2010 4:03 PMThank you for answering my question, I thought I was doing something wrong, since this is my very first time using oci.
I do see non-null terminated strings mentioned from places to places on the oracle docs, but I don't see it mentioned specifically on the attribute OCI_ATTR_NAME.
Anyway, as long as I have the string length returned by the function call, then it's all good. Thank you again!! -
Using values returned from SQL for Report column names
I am building reports against our TFS development db.
One of the reports tracks days spent (Dwell Time) in various status categories (eg: New, Assigned, In Development, Hold, etc) for a given "ticket".
For a fixed list of values from {Work Item].System_State, I can send the results (days in Assigned) to the column named (Assigned) for each status for each event in the [Work Item History], and then sum them for each ticket as:
Ticket ID New Assigned InDev etc
1230001 2 0 0 ...
1230001 0 1 2 ....
SUM 2 1 2 ....
However, I have many different Projects, each of which use their own Status names.
I don't want to duplicate the same basic report, if I can avoid it.
How can I name and generate this data for the unique Status list for each Project?
Simplest analog is: name = First(Fields!Status.Value, "TFSdb")
and allows value for a column name (category) as: =IIF(Fields!Status.Value = First(Fields!Status.Value, "TFSdb"), Fields!Days.Value, 0)
However this fails beause:
1. It only delivers the FIRST status value, and,
2. I cannot SUM an expression which is itself an aggregate (using First).RRapport,
Is this still an issue?
Thanks!
Ed Price, Power BI & SQL Server Customer Program Manager (Blog,
Small Basic,
Wiki Ninjas,
Wiki)
Answer an interesting question?
Create a wiki article about it!
Maybe you are looking for
-
how can I get all of my music off of my laptop and onto an external hard drive? I bought a new hard drive for it but it got turned into a Time Machine drive... I want to have all of my music on the external hard drive, and NOT on my macbook pro. T
-
File sharing with Airport Extreme
I've recently upgraded my Linksys wireless router with an Airport Extreme base station. Using the Linksys router, I was able to share files between my Macbook and my XP desktop. Now I can't seem to establish that connection. I should have everything
-
Call SOAP Adapter from CE BPM failed
Hi everyone, i have just a problem calling a webservic on the PI 7.11 server from CE 7.2 BPM via SOAP adapter. 1. I've created a very simple scenario on the PI 7.11 Server using SOAP Adapter sender. I've gotten the WSDL URL from the Sender Agreement.
-
Not firing valueUnbound for HttpSessionBindingListener
Hi, Having an application deployed in Websphere 5.1. When the session is created for a user, valueBound() is called properly. Session timeout has been set to 10 mins. On timeout, it is suppose to call the valueUnbound(). It was tested and found to be
-
Compiling Apache2 on Tiger (not server)
Hi all, I've been developing Unix apps for over 17 years. My primary platform was Linux and that's now secondary. My PowerMac Dual running Tiger (not server) is my primary. I disabled the stock Apache 1.3, then downloaded the latest Apache2 code (2.2