1)我正在製作一個應用程序,在其中顯示摘要表。在點擊每個彙總列時,我可以按升序或降序進行排序。例如有5列動態SQL查詢創建
2)所以在一個普通的實例中,我將創建最少5個單獨的sql查詢來提供此功能。這可以創建爲準備好的語句。
3),但它是一個很好的做法,建立一個單一的動態SQL代碼,可以考慮到所有有條件的地方通過&如我在下面做了所有的訂單?它將如何影響數據庫性能?從現在開始我不能寫任何準備好的陳述,我的執行會很慢嗎?
請建議 感謝
CREATE DEFINER=`root`@`localhost` PROCEDURE `lSummary`(in fixedConditionList VARCHAR(1000),in OptionalConditionListForBackEnd VARCHAR(1000),in orderByColumnList VARCHAR(1000),in optionalJoinStatement VARCHAR(1000),in startLimit int(10),in OptionalFilterListWithAnd VARCHAR(1000),in OptionalFilterListWithOr VARCHAR(1000),in selectColumnList VARCHAR(10000),in EndLimit int(10)) BEGIN DECLARE SQLStatement varchar(5000); SET @SQLStatement = CONCAT("select l.lCaseId,concat('Staf') as canWrite,concat('Staf') as canShare,DATE_FORMAT(c.nextCourtDate,'%d-%m-%Y') as nextCourtDate,TIME_FORMAT(c.nextTime,'%h:%i %p') as nextTime,totalNumberOfSSteps,totalNumberOfSteps, ",selectColumnList," from litigation l left join(select relatedToId,relatedToPrefix,count(*) as totalNumberOfSteps from flowsubmilestoneinuse group by relatedToId) as wt on l.lCaseId=wt.relatedToId and l.lCasePrefix=wt.relatedToPrefix left join (select relatedToId,relatedToPrefix,count(*) as totalNumberOfSSteps from flowsubmilestoneinuse where milestoneReachedById Is not null group by relatedToId ) as wc on l.lCaseId=wc.relatedToId and l.lCasePrefix=wc.relatedToPrefix left join detail c on c.lCaseId= l.lCaseId ",optionalJoinStatement," where (",fixedConditionList,") AND (",OptionalConditionListForBackEnd,") AND (",OptionalFilterListWithAnd,") AND (",OptionalFilterListWithOr,") order by ",orderByColumnList," Limit ",startLimit,EndLimit); EXECUTE STMT; END
當然,準備好的語句可以在運行時接受動態參數。這不是問題。 – arkascha
嗨,你可以請指導我參考一些教程,如果可能的話。謝謝 – Lajpat