Oracle表多列模糊查询存储过程改造需求
How to Modify Oracle Stored Procedure for Full-Column Search
Got it, let's fix up your stored procedure to support searching across all columns in the APPLICATION_MASTER table instead of just APPLICATIONNAME.
The Modified Procedure
Here's the updated code that checks every column for a match with the input text:
PROCEDURE GET_SEARCH_DATA ( P_INPUTTEXT IN NVARCHAR2, P_RETURN OUT SYS_REFCURSOR ) AS BEGIN OPEN P_RETURN FOR SELECT APP_MST_ID, APPLICATIONNAME, PROJECTNO, VSS_FOLDER_LOC FROM APPLICATION_MASTER WHERE -- Check each character column directly APPLICATIONNAME LIKE '%' || P_INPUTTEXT || '%' OR PROJECTNO LIKE '%' || P_INPUTTEXT || '%' OR VSS_FOLDER_LOC LIKE '%' || P_INPUTTEXT || '%' -- Convert numeric column to string to avoid type mismatch (adjust if APP_MST_ID is not numeric) OR TO_CHAR(APP_MST_ID) LIKE '%' || P_INPUTTEXT || '%'; END;
Key Details to Note
- Data Type Compatibility: If
APP_MST_IDis a numeric type (likeNUMBER), we useTO_CHAR()to convert it to a string before applying theLIKEcondition—this prevents type mismatch errors. If it's already a character column, you can remove theTO_CHAR()wrapper. - Handling NULLs: If any column might have
NULLvalues and you want to treat them as empty strings for matching, wrap the column inNVL()like this:NVL(APPLICATIONNAME, '') LIKE '%' || P_INPUTTEXT || '%' - Performance Tip: Full-column
LIKEqueries can slow down on large tables. If performance becomes an issue, consider using Oracle's Text Indexing (like creating aCONTEXTindex) to optimize keyword searches across multiple columns.
内容的提问来源于stack exchange,提问作者Nadeem
相关产品推荐
相关产品推荐

