简体   繁体   中英

Tableau Oracle DB SQL column name select with spaces

I am using custom SQL query in Tableau which is connected to a table in an Oracle DB. I have some column names with spaces and some without spaces. I get an error if I use a column name with space. Please see below:

Column Names
"Department"
"Job Type"

Methods used for column name WITHOUT space

SELECT Department FROM OG_COCKPIT_HC_CONTR_V -- (WORKS!)

SELECT (Department) FROM OG_COCKPIT_HC_CONTR_V -- (WORKS!)

SELECT "Department" FROM OG_COCKPIT_HC_CONTR_V -- (DOESN'T WORK)

SELECT [Department] FROM OG_COCKPIT_HC_CONTR_V -- (DOESN'T WORK)

SELECT 'Department' FROM OG_COCKPIT_HC_CONTR_V -- (DOESN'T WORK)

For the "Job Type" field none of the above works. Do you know what is the right syntax?

SELECT "Department","Job Type" FROM OG_COCKPIT_HC_CONTR_V 

should work fine, but keep in mind is case sensitive.

Ted.

If SELECT Department ... works but SELECT "Department" ... doesn't work, then it means that column Department was defined without double quotes and is case insensitive. All following statements should work fine:

select Department, "Job Type" FROM og_cockpit_hc_contr_v;
select department, "Job Type" FROM og_cockpit_hc_contr_v;
select DEPARTMENT, "Job Type" FROM og_cockpit_hc_contr_v;

Probably a typo in Job Type? Consider an example below:

SQL>     create or replace view og_cockpit_hc_contr_v as 
         select 'Dep1' as Department, 'Dummy' as "Job Type" from dual
         ;

SQL>     select column_name from user_tab_cols 
         where table_name= 'OG_COCKPIT_HC_CONTR_V'
         and (upper(column_name) like 'JOB%' or upper(column_name) like'DEP%')
         ;

COLUMN_NAME
-----------------
DEPARTMENT
Job Type

SQL>     col department for a10
SQL>     col "Job Type" for a10
SQL>     select Department, "Job Type" FROM og_cockpit_hc_contr_v;

DEPARTMENT Job Type
---------- ----------
Dep1       Dummy

Note: Oracle does not recommend using quoted identifiers for database object names. These quoted identifiers are accepted by SQL*Plus, but they may not be valid when using other tools that manage database objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM