a)
\({x^2} - 9 + xy + 3y \\= \left( {{x^2} - 9} \right) + \left( {xy + 3y} \right) \\= \left( {x - 3} \right)\left( {x + 3} \right) + y\left( {x + 3} \right) \\= \left( {x + 3} \right)\left( {x - 3 + y} \right)\)
b)
\({x^2}y + {x^2} + xy - 1 \\= \left( {{x^2}y + xy} \right) + \left( {{x^2} - 1} \right) \\= xy\left( {x + 1} \right) + \left( {x + 1} \right)\left( {x - 1} \right) \\= \left( {x + 1} \right)\left( {xy + x - 1} \right)\)