Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2009
    Posts
    21

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Try putting the table name in double quotes. Obviously, you will have to escape them because they will be withing another quoted string.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    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.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    You have to quote the entire statement AND the table name.
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Sep 2003
    Posts
    237
    Try db2 "select count(*) from '/BIC/AZAR_D0500' "
    mota

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by dbamota
    Try db2 "select count(*) from '/BIC/AZAR_D0500' "
    Not gonna work. Must be double quotes, like I said.
    ---
    "It does not work" is not a valid problem statement.

  7. #7
    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..

  8. #8
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    ---
    "It does not work" is not a valid problem statement.

  9. #9
    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

  10. #10
    Join Date
    Mar 2009
    Posts
    21
    yes but did not work..i tried with single quote as well double quote...

  11. #11
    Join Date
    Jan 2009
    Posts
    8
    please try it with "select count(*) from SAPDB1./BIC/AZAR_D0500".

  12. #12
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    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/

  13. #13
    Join Date
    May 2007
    Location
    somewhere in dbforums
    Posts
    221
    In OS command prompt you can try
    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
    select count(*) from SAPDB1."/BIC/AZAR_D0500"
    both will work
    IBM Certified Database Associate, DB2 9 for LUW

  14. #14
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  15. #15
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •