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 > Error when counting the records for table name starting with '/'

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-13-09, 10:23
db2raja db2raja is offline
Registered User
 
Join Date: Mar 2009
Posts: 21
Error when counting the records for table name starting with '/'



Hi All,
I am using the following sql to count the records from a table that is starting with '/'. the error is as follows.

I am using DB2 v9.1.5
OS - AIX 5.3

db2 "select count(*) from SAPDB1./BIC/AZAR_D0500"
SQL0104N An unexpected token "count(*) from SAPDB1." was found following
"select ". Expected tokens may include: "<term>". SQLSTATE=42601

Please help.

Thanks
Raja
Reply With Quote
  #2 (permalink)  
Old 03-13-09, 10:42
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Try putting the table name in double quotes. Obviously, you will have to escape them because they will be withing another quoted string.
Reply With Quote
  #3 (permalink)  
Old 03-13-09, 10:51
db2raja db2raja is offline
Registered User
 
Join Date: Mar 2009
Posts: 21
Hi Nick, Thanks for ur reply.. I am trying like this but still it is giving error.. correct me in the syntax if it is wrong.

db2 select count(*) from "/BIC/AZAR_D0500"
ksh: 0403-057 Syntax error: `(' is not expected.
Reply With Quote
  #4 (permalink)  
Old 03-13-09, 12:58
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You have to quote the entire statement AND the table name.
Reply With Quote
  #5 (permalink)  
Old 03-13-09, 12:59
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
Try db2 "select count(*) from '/BIC/AZAR_D0500' "
__________________
mota
Reply With Quote
  #6 (permalink)  
Old 03-13-09, 13:00
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by dbamota
Try db2 "select count(*) from '/BIC/AZAR_D0500' "
Not gonna work. Must be double quotes, like I said.
Reply With Quote
  #7 (permalink)  
Old 03-13-09, 14:18
db2raja db2raja is offline
Registered User
 
Join Date: Mar 2009
Posts: 21
db2db1> db2 "select count(*) from SAPDB1."/BIC/AZAR_D0500""
SQL0104N An unexpected token "count(*) from SAPDB1." was found following
"select ". Expected tokens may include: "<term>". SQLSTATE=42601

db2db1> db2 "select count(*) from SAPDB1.'/BIC/AZAR_D0500'"
SQL0104N An unexpected token "'/BIC/AZAR_D0500'" was found following "ount(*)
from SAPDB1.". Expected tokens may include: "<identifier>". SQLSTATE=42601

db2db1> db2 "select count(*) from "SAPDB1"."/BIC/AZAR_D0500""
SQL0104N An unexpected token "count(*) from SAPDB1." was found following
"select ". Expected tokens may include: "<term>". SQLSTATE=42601

None of these has worked..
Reply With Quote
  #8 (permalink)  
Old 03-13-09, 14:49
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Reply With Quote
  #9 (permalink)  
Old 03-13-09, 15:00
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
Did you try db2 "select count(*) from 'SAPDB1./BIC/AZAR_D0500'"
You have to put the total table name within single quote
__________________
mota
Reply With Quote
  #10 (permalink)  
Old 03-13-09, 16:54
db2raja db2raja is offline
Registered User
 
Join Date: Mar 2009
Posts: 21
yes but did not work..i tried with single quote as well double quote...
Reply With Quote
  #11 (permalink)  
Old 03-13-09, 19:11
arun-dba arun-dba is offline
Registered User
 
Join Date: Jan 2009
Posts: 8
please try it with "select count(*) from SAPDB1./BIC/AZAR_D0500".
Reply With Quote
  #12 (permalink)  
Old 03-13-09, 20:10
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Wouldn't the following work?
Code:
db2 'select count(*) from SAPDB1."/BIC/AZAR_D0500" '
Or otherwise try
Code:
db2 'select count(*) from "SAPDB1./BIC/AZAR_D0500" '
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #13 (permalink)  
Old 03-14-09, 02:19
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
In OS command prompt you can try
Quote:
db2 "select count(*) from SAPDB1.\"/BIC/AZAR_D0500\""
note that the '\' here acts as an escape character to your "

In the db2 command prompt you can try
Quote:
select count(*) from SAPDB1."/BIC/AZAR_D0500"
both will work
__________________
IBM Certified Database Associate, DB2 9 for LUW
Reply With Quote
  #14 (permalink)  
Old 03-15-09, 15:31
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by dbamota
Did you try db2 "select count(*) from 'SAPDB1./BIC/AZAR_D0500'"
You have to put the total table name within single quote
That will never work because a single quote is a string delimiter while you have to use double-quotes for delimited identifiers. You will have to switch single and double quotes here.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #15 (permalink)  
Old 03-16-09, 16:04
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
Created table as follows
db2test2@egudbw:/dbhome/db2test2/bas> cat zz
CREATE TABLE COMMON."/BIC/AZAR_D0500"(
MSG_ID VARCHAR(30),
MESSAGE VARCHAR(255)
) in userspace1;

created a file y

db2test2@egudbw:/dbhome/db2test2/bas> cat y
select count(*) from COMMON."/BIC/AZAR_D0500";



db2test2@egudbw:/dbhome/db2test2/bas> db2 -tvf y
select count(*) from COMMON."/BIC/AZAR_D0500"

1
-----------
0
__________________
mota
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