Complete the code to extract the first 5 characters from the string 'HelloWorld'.
SELECT SUBSTRING('HelloWorld' FROM 1 FOR [1]);
The SUBSTRING function extracts a part of the string starting at position 1 for 5 characters.
Complete the code to replace 3 characters starting at position 2 in 'abcdef' with 'XYZ'.
SELECT OVERLAY('abcdef' PLACING [1] FROM 2 FOR 3);
The OVERLAY function replaces 3 characters starting at position 2 with 'XYZ'.
Fix the error in the code to extract substring starting at position 3 with length 4 from 'PostgreSQL'.
SELECT SUBSTRING('PostgreSQL' [1] 3 FOR 4);
The correct syntax uses FROM to specify the start position in SUBSTRING.
Fill both blanks to extract 4 characters starting at position 2 from 'Database' and replace them with '1234'.
SELECT OVERLAY('Database' PLACING [1] FROM [2] FOR 4);
The OVERLAY replaces 4 characters starting at position 2 with '1234'.
Fill all three blanks to extract substring starting at position 4 for 3 characters from 'Programming' and replace it with 'XYZ'.
SELECT OVERLAY(SUBSTRING('Programming' FROM [1] FOR [2]) PLACING [3] FROM 1 FOR 3);
First, SUBSTRING extracts 3 characters starting at position 4, then OVERLAY replaces them with 'XYZ'.