打印本文 打印本文 关闭窗口 关闭窗口
使用动态SQL(ASE12.0+)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数846  更新时间:2009/4/22 23:09:40  文章录入:mintao  责任编辑:mintao

With a certain regularity, Sybase users ask questions like "How can I use dynamic SQL in ASE ?" in the Sybase-related newsgroups. There are a number of different answers to this question.

The elegant way: execute-immediate (ASE 12.0+)
First, if you're running ASE 12.0 or later, you can use the execute immediate feature, which gives you full dynamic SQL capabilites, as it lets you execute dynamically generated SQL command strings. A simple example:

declare @c varchar(25)
select @c = "select getdate()"
exec (@c)

While this example is hardly something to get excited about, execute-immediate has opened a new dimension to the sort of thing you can do with T-SQL. The most important characteristic is that you can now create stored procedures (and triggers) that are independent of the schema of tables -- a highly useful thing to do.
My book "Tips, Tricks & Recipes for Sybase ASE" has a chapter dedicated to execute-immediate, describing not only the inner workings, but also a wide range of possible applications. This is probably the most complete writeup about execute-immediate that's available.



关闭本页  

打印本文 打印本文 关闭窗口 关闭窗口