2012-01-23 59 views
1
當我運行的存儲過程和通過「其中tbl_property.intId = 1」它使程序執行失敗 1243的參數
Below is my store procedure .please help........ 



BEGIN 



DECLARE selectQuery VARCHAR(2000); 
declare finalquery varchar(2000); 
declare stmt3 varchar(2000); 

SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms 
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intPro 
set finalquery =CONCAT(selectQuery,strSqlQuery,' AND tbl_property.intId=1 '); 

execute finalquery; 

END 

在MySQL執行語句 - 未知準備語句處理程序(最後查詢)給EXECUTE如何使用,同時使用動態where子句

以及我檢查查詢結果通過選擇語句它給出了正確的查詢和返回結果。所以請幫助我使用Execute語句。

+0

SQL語法用於預處理語句 - HTTP://dev.mysql。 com/doc/refman/5.1/en/sql-syntax-prepared-statements.html – Devart

回答

0

嘗試此鏈接http://docs.oracle.com/javase/tutorial/jdbc/basics/storedprocedures.html,它可以幫助你, BEGIN

DECLARE selectQuery VARCHAR(2000); 
declare finalquery varchar(2000); 
declare stmt3 varchar(2000); 

SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms 
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intProId '; 

set finalquery =CONCAT(selectQuery,strSqlQuery); 


EXECUTE finalquery; 
0

動態語句必須準備和使用後釋放。這是一個例子。

BEGIN 

SET @selectQuery = 'SELECT * from table1 where' 

SET @QUERY = CONCAT(@selectQuery, ' field = 1');    
SELECT @QUERY; 
PREPARE s FROM @QUERY; 

EXECUTE s; 
DEALLOCATE PREPARE s; 

END 
2

Thanxs您的幫助,我已經嘗試過了,它很少modifications..below工作是我的存儲過程:

BEGIN 
DECLARE selectQuery VARCHAR(2000); 
declare finalquery varchar(2000); 

SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms 
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intProId '; 

set @finalquery =CONCAT(selectQuery,strSqlQuery,' AND tbl_property.intId=1 '); 

PREPARE result from @finalquery; 
EXECUTE result; 
DEALLOCATE PREPARE result; 

END 
+0

當系統允許您將此標記爲接受的答案時,或將其編輯爲您的問題並接受幫助您的答案最多。 –

+0

並指出你已經改變了。 – levi