我想根據從gui中選擇的標準動態構建查詢。這裏是我的Oracle包,函數返回varchar2給出錯誤結果
CREATE OR REPLACE PACKAGE TestPkg
AS
g_lastnamelist VARCHAR2(50);
FUNCTION getLastName return VARCHAR2;
FUNCTION buildQuery(p_lastnamelist VARCHAR2);
END;
CREATE OR REPLACE PACKAGE BODY TestPkg
AS
FUNCTION getLastName return VARCHAR2
IS
BEGIN
RETURN replace(g_lastnamelist, '''', '');
END;
FUNCTION buildQuery(p_lastnamelist VARCHAR2);
IS
m_query varchar2(1000);
BEGIN
g_lastnamelist := p_lastnamelist;
m_query := 'SELECT * FROM emp WHERE last_name IN(TestPkg.getLastName)';
END;
END;
這裏如果我使用'SELECT * FROM emp WHERE last_name IN('||p_lastnamelist||')';
然後返回我正確的記錄,但如果我使用'SELECT * FROM emp WHERE last_name IN(TestPkg.getLastName)';
這個樣子,那麼它失敗。什麼原因。
在此先感謝。
好綽號! – 2013-04-22 12:39:00
@EgorSkriptunoff謝謝。 :) – eatSleepCode 2013-04-22 13:14:37