Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 691509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:33:06+00:00 2026-05-14T02:33:06+00:00

This seems like it should be very easy…anyway, it is in MS SQL Server

  • 0

This seems like it should be very easy…anyway, it is in MS SQL Server

In a DB2 stored procedure, how can I just get the value of a variable? Say I have the following stored procedure:

CREATE PROCEDURE etl.TestABC( 
) 
LANGUAGE SQL 
  BEGIN 
    declare      Stmt              varchar(2048); 
    set Stmt = 'this is a test';
-- print Stmt;
-- select Stmt;


    return 0; 
END @ 

I’d like to print out the value of Stmt after I set it. Print doesn’t work, select doesn’t work. Somebody said I have to insert it to a table first, and then get it after I run the stored procedure. Is this really necessary?

Thanks,
Sylvia

EDIT: I should have made clearer that I want to see the value of Stmt each time after I set it, and I may need to set it multiple times within the same stored procedure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:33:06+00:00Added an answer on May 14, 2026 at 2:33 am

    If you want to see the values while you’re developing / testing your stored procedure, then you should use IBM Data Studio and debug your stored procedure. This provides normal debugger functionality, so you can see the value of variables as your procedure executes.

    If, however, you just want to execute your stored procedure and see a history of values, I suggest creating a global temporary table, and inserting a row into it in your code:

    declare global temporary table StmtHistory (
      when timestamp not null with default current timestamp, 
      stmt varchar(2048) not null
      ) on commit preserve rows;
    

    Then, at points in your stored procedure, add:

    insert into session.StmtHistory (stmt) values (stmt);
    

    After you execute your stored procedure, you can query the table session.StmtHistory and see the values you’re looking for.

    Also, DB2 9.7 added Oracle compatibility, so if you are using this version you may actually be able to use DBMS_OUTPUT.PUT_LINE and DBMS_OUTPUT.GET_LINES to accomplish this, if you prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.