在動態SQL構建中,可以使用SUBSTR函數來截取字符串的子串。以下是一些SUBSTR函數在動態SQL構建中的應用方法:
SELECT SUBSTR(column_name, start_position, length) FROM table_name;
SELECT * FROM table_name WHERE SUBSTR(column_name, start_position, length) = 'substring';
SELECT * FROM table_name ORDER BY SUBSTR(column_name, start_position, length);
DECLARE
v_start_position NUMBER := 1;
v_length NUMBER := 5;
BEGIN
EXECUTE IMMEDIATE 'SELECT * FROM table_name WHERE SUBSTR(column_name, ' || v_start_position || ', ' || v_length || ') = ''substring''';
END;