If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Db2 select statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-22-09, 18:01
Pollyanna Smith Pollyanna Smith is offline
Registered User
 
Join Date: Feb 2009
Posts: 9
Db2 select statement

Hello Expert,

I have a table with the name /SCM/DF_D_TYPE.

I can execute the command to describe the table.

db2 describe table SAPDEV./SCMB/DF_D_TYPE

Data type Column
Column name schema Data type name Length Scale N
ulls
------------------------------- --------- ------------------- ---------- ----- -
-----
CLIENT SYSIBM CHARACTER 3 0 N
o
CATEGORY SYSIBM VARCHAR 4 0 N
o
DF_LEVEL SYSIBM CHARACTER 1 0 N
o

3 record(s) selected.

When I tried to execute the following select statement:

db2 "select * from SAPDEV./SCMB/DF_D_TYPE"
SQL0104N An unexpected token "* from SAPDEV." was found following "select ".
Expected tokens may include: "<term>". SQLSTATE=42601

What is the correct way to referencing the table name with '/'?

Thanks in Advance!

Pollyanna
Reply With Quote
  #2 (permalink)  
Old 10-22-09, 18:19
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Try:

db2 "select * from SAPDEV.\"/SCMB/DF_D_TYPE\""
Reply With Quote
  #3 (permalink)  
Old 10-23-09, 08:57
Pollyanna Smith Pollyanna Smith is offline
Registered User
 
Join Date: Feb 2009
Posts: 9
Bella,

Thanks for your response,

When I executed your suggested statement:

db2 "select * from SAPDEV.\"/SCMB/DF_D_TYPE\""
Unmatched ".

It seems that the characters \" around the table name /SCMB/DF_D_TYPE confused db2 interpreter.
Reply With Quote
  #4 (permalink)  
Old 10-23-09, 09:31
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Works for me:


test@p6db2serv /home/test > db2 list tables for schema SAPDEV

Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
/SCMB/DF_D_TYPE SAPDEV T 2009-10-23-09.25.49.231186

1 record(s) selected.

test@p6db2serv /home/test > db2 "select * from SAPDEV.\"/SCMB/DF_D_TYPE\""

COL1
-----------
132

1 record(s) selected.
Reply With Quote
  #5 (permalink)  
Old 10-24-09, 13:06
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If you use special characters in identifiers, you need so-called "delimited identifiers". Those are described in the manual.

The major issue with such identifiers is usually not DB2 but rather your shell. For example, on UNIX systems, the shell interprets single and double quotes, interfering with the SQL statement. You can avoid this by properly escaping characters with special meaning to a shell (e.g. *, ?, ", ') or you can work with the DB2 CLP to take the shell out of the picture.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 10-26-09, 09:36
Pollyanna Smith Pollyanna Smith is offline
Registered User
 
Join Date: Feb 2009
Posts: 9
I resolved the problem by using single qote:

db2 'select * from SAPDEV."/SCMB/DF_D_TYPE"'

I used the single quote to wrap the SQL select statement. I used the double quote to qualify the special character /.

Thank you for your response.
Reply With Quote
  #7 (permalink)  
Old 10-26-09, 13:12
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Where I come from, people who use special characters (other than underscore) in table and/or column names are tarred and feathered. In Singapore, you get 100 lashes.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #8 (permalink)  
Old 10-26-09, 18:11
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Don't know the reason why... but SAP loves to put '/' in their table names.
Reply With Quote
  #9 (permalink)  
Old 10-26-09, 19:35
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I guess they don't use SAP much in Singapore...
Reply With Quote
  #10 (permalink)  
Old 10-26-09, 20:00
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by db2girl
Don't know the reason why... but SAP loves to put '/' in their table names.
Must be a German thing. Maybe Stolze knows.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #11 (permalink)  
Old 10-26-09, 21:20
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
I think it has something to do with "SAP namespaces".

From http://www.ibm.com/developerworks/fo...geID=13979880:

"In an SAP system there are so called name spaces for dictionary objects like database tables. The name space identifier consists of a forward slash, the name space name and another forward slash. The identifier is then part of the table name. For example the table that holds the service download customizing is called "/bdl/cust", with "bdl" being the name space."
Reply With Quote
  #12 (permalink)  
Old 10-27-09, 13:44
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by Marcus_A
Must be a German thing. Maybe Stolze knows.
To, I don't. Usually, I have to consider delimited identifiers because what I'm working with is rather close to the database engine and I don't know what customers are doing.

My guess on this thing is that SAP supports a wide variety of different DBMS as backend. Maybe there is even a file-based storage system possible.And because all common operating systems use '/' as directory separator, it be a way to organize things on disk without getting too big directories.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On