Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic tablename in function 1

Status
Not open for further replies.

Naranek

Programmer
Apr 29, 2003
4
0
0
NO
Hello Experts,

I am trying to pass a tablename into a function and return the rowcount for the given table.

I made it Sybase using a string variable and a cursor. Is there a simular way to build a string, then use the string as the SQL statment for a cursor?

my_sql := 'SELECT COUNT(*) FROM ' + my_tablename + ';';

Is there any way to send my_sql to the cursor? Or is the a better way?

Any suggestions are most welcome!


Best Regards,
Gunnar
 
In Oracle, you would use dynamic SQL:
Code:
my_sql := 'SELECT COUNT(*) FROM ' || my_tablename;
EXECUTE IMMEDIATE my_sql INTO v_count;

RETURN (v_count);

 
Yes, thanks.

Quite easy once you know it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top