我的桌子有一些内部预先修复,用户不得知道 所以我做了这样的SP来检索线条。
CREATE PROCEDURE p_Test
( inStation varchar(10) )
RETURNS
( ServiceName varchar(20) )
AS
DECLARE VARIABLE StationTable varchar(20);
BEGIN
StationTable = 'TSTATION_' || Upper(Trim(inStation));
SELECT StationTable.ServiceName
FROM StationTable
INTO :ServiceName;
suspend;
END^
我收到了这样的失败消息
SQL错误代码= -204
表未知
STATIONTABLE
我的fbclient.dll版本是2.1.2.18118 我的测试环境是Flamerobin 0.9.2.1851。
任何想法让这项工作?
答案 0 :(得分:2)
你可以尝试使用execute block:
execute block (inStation varchar(10) = ?)
returns (ServiceName = varchar(20))
as
DECLARE variable SQL Varchar(300);
DECLARE VARIABLE StationTable varchar(20);
begin
StationTable = 'TSTATION_' || Upper(Trim(inStation));
SQL := 'SELECT ' || StationTable ||'.ServiceName FROM ' || StationTable || ' INTO :ServiceName;';
execute STATEMENT sql;
SUSPEND;
end
检查here
答案 1 :(得分:0)
感谢您的提示,@ Hugues Van Landeghem。我使用两个关键字EXECUTE STATEMENT
使其工作。这是我的SP:
CREATE PROCEDURE p_Test ( inStation varchar(10) )
RETURNS ( ServiceName varchar(20) )
AS
DECLARE VARIABLE StationTable varchar(20);
BEGIN
StationTable = 'TSTATION_' || Upper(Trim(inStation));
EXECUTE STATEMENT 'SELECT ServiceName FROM ' || StationTable INTO :ServiceName;
SUSPEND;
END^