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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.