本文介绍了如何在SQL Anywhere中创建动态存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在SQL Anywhere中创建动态sql语句时遇到问题。I'm having an issue with creating dynamic sql statement in SQL Anywhere.CREATE PROCEDURE pplAnalysisASBEGIN DECLARE @Sql NVARCHAR(4000) SELECT @Sql = "select * from cds.ppl" EXECUTE(@Sql)END当我执行这个程序时, 列'select * from cds.ppl'not found 错误。When I execute this procedure, I get an Column 'select * from cds.ppl' not found error.你能告诉我我在做什么错误?Can you please tell me what am I doing wrong?推荐答案问题与语法和 RESULT 条款;在添加分号和 RESULT 子句后,并使用 SET 初始化Sql变量,这里是有效的任何网络服务器版本12.0.1):The issue had to do with syntax and the RESULT clause; after adding semicolons, RESULT clause, and used SET to initialize the Sql variable, here is what worked (tested in SQL Anywhere Network Server Version 12.0.1):drop proc pplAnalysis;CREATE PROCEDURE pplAnalysis()RESULT (cnot CHAR(5), cnull CHAR(5), vnot VARCHAR(5), vnull VARCHAR(5), explanation VARCHAR(50))BEGIN DECLARE @Sql NVARCHAR(4000); SET @Sql = 'select cnot, cnull, vnot, vnull, explanation from dbo.spaces'; EXECUTE ( @Sql );END; spaces c $ c> dbo 模式,这些列与 RESULTspaces is a table in the dbo schema and those columns are the same type specified in RESULT测试这两种方式执行过程,并返回结果:Tested these two ways to execute the procedure and both returned result:call pplAnalysis();cnot cnull vnot vnull explanation----- ----- ----- ----- --------------------------------------------------Execution time: 0.027 secondsProcedure completed或exec pplAnalysis;cnot cnull vnot vnull explanation----- ----- ----- ----- --------------------------------------------------Execution time: 0.018 seconds有关详情: 从程序返回结果集 创建过程语句 这篇关于如何在SQL Anywhere中创建动态存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 20:02