Db2 (On Premises and Cloud)

Expand all | Collapse all

DB2

  • 1.  DB2

    Posted Fri May 21, 2021 10:48 AM
    Hi ,

    When i try to communicate with DB2 data base by using the procedure in the visual studio.
    I am getting the below error.
    Error: [IBM][CLI Driver][DB2/NT64] SQL0104N An unexpected token "DONATES" was found following "LECT * FROM XY87172.". Expected tokens may include: "END". LINE NUMBER=4. SQLSTATE=42601

    I run by goin through the view command platte...
    I installed db2 extension in the visual studio.

    CREATE PROCEDURE fetech
    LANGUAGE SQL
    BEGIN
        SELECT * FROM XY87172.DONATES;
    END;


    ------------------------------
    Narasimha Nannuri
    ------------------------------


  • 2.  RE: DB2

    Posted Mon May 24, 2021 01:57 AM
    the delimiter is used twice
    after the END put another character like @ and change in VS the default delimiter


    ------------------------------
    Thank for all update/help
    Best Regards, Guy Przytula
    ------------------------------



  • 3.  RE: DB2

    Posted Mon May 24, 2021 03:50 AM
    Hi Guy,
    Very thanks to response. I tried this too 

    CREATE PROCEDURE fetech()
    LANGUAGE SQL
    BEGIN
        SELECT ID FROM DONATES;
    END@


    But getting the below error.

    CREATE PROCEDURE fetech() LANGUAGE SQL BEGIN SELECT ID FROM DONATES ;

    Error: [IBM][CLI Driver][DB2/NT64] SQL0104N An unexpected token "SELECT ID" was found following "ANGUAGE SQL BEGIN ". Expected tokens may include: "<space>". LINE NUMBER=4. SQLSTATE=42601

    END@ ;

    Error: [IBM][CLI Driver][DB2/NT64] SQL0104N An unexpected token "END-OF-STATEMENT" was found following "END@". Expected tokens may include: "JOIN <joined_table>". SQLSTATE=42601</joined_table></space>






    ------------------------------
    Narasimha Nannuri
    ------------------------------



  • 4.  RE: DB2

    Posted Mon May 24, 2021 04:14 AM
    reading the doc is to first step if you have never created a proc
    https://www.ibm.com/docs/en/db2/11.5?topic=statements-create-procedure-sql

    CREATE PROCEDURE fetech
    LANGUAGE SQL
    BEGIN
    declare tt date ;
    SELECT current date into tt from sysibm.sysdummy1 ;
    end@

    DB20000I The SQL command completed successfully

    ------------------------------
    Thank for all update/help
    Best Regards, Guy Przytula
    ------------------------------



  • 5.  RE: DB2

    Posted Mon May 24, 2021 04:38 AM
    I tried this to after reading this document. I wrote a new procedure.
    CREATE PROCEDURE GetCarsByMake
    @PROJECT_ID INTEGER
    AS
    BEGIN
    SELECT *
    FROM DONATES
    WHERE PROJECT_ID = @PROJECT_ID
    END
    GO


    Getting the below error.

    QUERY: CREATE PROCEDURE GetCarsByMake @PROJECT_ID INTEGER AS BEGIN SELECT * FROM DONATES WHERE PROJECT_ID = @PROJECT_ID END GO ;

    Error: [IBM][CLI Driver][DB2/NT64] SQL0104N An unexpected token "@PROJECT_ID INTEGER AS" was found following "DURE GetCarsByMake ". Expected tokens may include: "<space>". LINE NUMBER=3. SQLSTATE=42601</space>

    Number of Rows returned: undefined.

    But thanks allot for your reply .

    I am running in the visual studio code .after database sucess


    view -> command Platte... -> DB2: Execute current sql file -> It its opening a box "Enter delimeter for SQL in the selected file". I am not entering any thing in the delimeter directly clk enter. I am getting the error.






    ------------------------------
    Narasimha Nannuri
    ------------------------------



  • 6.  RE: DB2

    Posted Mon May 24, 2021 06:08 AM
    I think, you should read it again
    what is : @PROJECT_ID INTEGER ? parameter in/out ?
    look at samples :
    (IN NUMBER INT, OUT PART_NAME CHAR(35))


    ------------------------------
    Thank for all update/help
    Best Regards, Guy Przytula
    ------------------------------



  • 7.  RE: DB2

    Posted Mon May 24, 2021 06:13 AM
    and you write 1 line of code with 20 errors ..    please read carefully - look at the samples in sqllib/samples... or in the doc
    SELECT * FROM DONATES WHERE PROJECT_ID = @PROJECT_ID

    where does the output goto  ? : look at sample : select col into var ....

    ------------------------------
    Thank for all update/help
    Best Regards, Guy Przytula
    ------------------------------



  • 8.  RE: DB2

    Posted Mon May 24, 2021 06:15 AM
    https://www.ibm.com/docs/en/developer-for-zos/9.1.1?topic=tutorials-create-test-deploy-db2-sql-stored-procedure

    ------------------------------
    Thank for all update/help
    Best Regards, Guy Przytula
    ------------------------------