storing a value from execute immediate

How can I store my count value when I execute the dynamic query at line 6 below?

1  queryString VARCHAR(200);
2  FINALVALUE int;
3  COUNTER int;

4   SELECT COUNT(1) INTO COUNTER FROM CLIENT -- gets the number of records -- Hurrah This works !!!!


5   queryString:='SELECT COUNT(1) INTO COUNTER FROM CLIENT';
6   FINALVALUE := execute immediate queryString;
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
 
sdstuberCommented:
first off - you shouldn't use execute immediate for static statements

But, if you just want to see how for academic reasons...


DECLARE
    querystring   VARCHAR(200);
    finalvalue    INT;
    counter       INT;
BEGIN
    SELECT COUNT(1) INTO counter FROM client;  -- gets the number of records -- Hurrah This works !!!!

    querystring := 'SELECT COUNT(1) FROM CLIENT';

    EXECUTE IMMEDIATE querystring INTO finalvalue;

    DBMS_OUTPUT.put_line(counter || ' ' || finalvalue);
END;

Open in new window

0
 
brgdotnetcontractorAuthor Commented:
Thanks for the help. When I execute the code I get an error message which I cannot get rid of. Do you know what is wrong?

*Cause:   An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2).
0
 
sdstuberCommented:
I don't know what the problem could be.  I ran that exact block without issues
0
 
brgdotnetcontractorAuthor Commented:
Thanks so much. It works now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.