Professional Web Applications Themes

two select statements on one line? - IBM DB2

is it possible to put two sql select statements on one line through the Command Line Processor? db2 => select * from table1; select * from table2; Of course you know this won't work, as the character ; is apparently not a command delimiter in db2. Does anyone know what it is? How would I do the above procedure of execute two sql statements in one pass?...

  1. #1

    Default two select statements on one line?

    is it possible to put two sql select statements on one line through
    the Command Line Processor?

    db2 => select * from table1; select * from table2;

    Of course you know this won't work, as the character ; is apparently
    not
    a command delimiter in db2. Does anyone know what it is?
    How would I do the above procedure of execute two sql statements in
    one pass?
    Kenjis Guest

  2. #2

    Default Re: two select statements on one line?

    Kenjis Kaan <com> wrote:
     

    Use a compound statement:

    BEGIN ATOMIC select * from table1; select * from table2; END

    The question is, however, what you want to do with the results...

    --
    Knut Stolze
    Information Integration
    IBM Germany / University of Jena
    Knut Guest

  3. #3

    Default Re: two select statements on one line?

    Kenjis Kaan wrote: 

    Interesting. Never tried this. You could make ; the delimiter by
    issuing, "db2 -t". But I am not sure how db2 is going to show the
    results on screen.

    W Guest

  4. #4

    Default Re: two select statements on one line?

    Depending on your needs, you can also do this...

    On windows, you can do the following.
    Parenthesis are not mandatory.

    & command separator
    && do 1, do 2 if 1 went ok
    || do 1, do 2 if 1 did not go ok


    I:\DB2USR\TEST>(db2 values 1)&(db2 values 2)

    1
    -----------
    1

    1 record(s) selected.


    1
    -----------
    2

    1 record(s) selected.


    I:\DB2USR\TEST>(db2 values 1)&&(db2 values 2)

    1
    -----------
    1

    1 record(s) selected.


    1
    -----------
    2

    1 record(s) selected.


    I:\DB2USR\TEST>(db2 values 1)||(db2 values 2)

    1
    -----------
    1

    1 record(s) selected.


    I:\DB2USR\TEST>(db2 values x'A1s')||(db2 values 2)
    SQL0105N The string constant beginning with "x'A1s" is not valid.
    SQLSTATE=42604

    1
    -----------
    2

    1 record(s) selected.




    PM


    PM Guest

  5. #5

    Default Re: two select statements on one line?

    "PM \(pm3iinc-nospam\)" <ca> wrote in message news:<xhhcb.1066$bellglobal.com>... 


    I am not sure why the && didn't work for me, although doing (values 1) by
    itself works. What am I missing. The goal of what I am doing is so I
    can execute multiple commands consecutively by passing it to db2clpex using
    this method.

    ---------------------------------------------

    db2 => values 1

    1
    -----------
    1

    1 record(s) selected.

    db2 => (values 1)&&(values 2)
    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0007N The character "&" following "(values 1)" is not valid.
    SQLSTATE=42601
    db2 => (values 1)&(values 2)
    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0007N The character "&" following "(values 1)" is not valid.
    SQLSTATE=42601
    db2 =>
    Kenjis Guest

  6. #6

    Default Re: two select statements on one line?

    Kenjis Kaan <com> wrote:
     

    I just needed the same thing and I found something that is working:

    /usr/bin/echo 'select * from table1\nselect * from table2' | db2

    But you have to have a look at the man page/help of the echo command to see
    what has to be done to interpret the '\n' as newline character. On Linux,
    you would have to add the option -e: echo -e '...\n...'.

    $ /usr/bin/echo "select count(*) from syscat.tables\nselect count(*) from
    syscat.views" | db2 -v
    (c) Copyright IBM Corporation 1993,2002
    Command Line Processor for DB2 SDK 8.1.3

    You can issue database manager commands and SQL statements from the command
    prompt. For example:
    db2 => connect to sample
    db2 => bind sample.bnd

    For general help, type: ?.
    For command help, type: ? command, where command can be
    the first few keywords of a database manager command. For example:
    ? CATALOG DATABASE for help on the CATALOG DATABASE command
    ? CATALOG for help on all of the CATALOG commands.

    To exit db2 interactive mode, type QUIT at the command prompt. Outside
    interactive mode, all commands must be prefixed with 'db2'.
    To list the current command option settings, type LIST COMMAND OPTIONS.

    For more detailed help, refer to the Online Reference Manual.

    db2 => select count(*) from syscat.tables
    1
    -----------
    280

    1 record(s) selected.

    db2 => select count(*) from syscat.views
    1
    -----------
    158

    1 record(s) selected.



    --
    Knut Stolze
    Information Integration
    IBM Germany / University of Jena
    Knut Guest

Similar Threads

  1. Combing two simple select statements. There must be a way?
    By ukr_bend@yahoo.com in forum MySQL
    Replies: 5
    Last Post: March 24th, 06:10 PM
  2. Use MS Access to write SQL select statements
    By StylusDesigns in forum Macromedia ColdFusion
    Replies: 2
    Last Post: June 1st, 11:37 PM
  3. Replies: 2
    Last Post: May 14th, 12:55 PM
  4. One line IF statements
    By JohnMathis webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 4
    Last Post: February 5th, 03:48 AM
  5. Using IF and IsNull statements in SELECT
    By oj in forum Microsoft SQL / MS SQL Server
    Replies: 2
    Last Post: July 2nd, 03:43 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139