3. Given that in the expansion of $\left(x^{2}-\frac{1}{x}\right)^{n}$, the constant term is 15. Then the value of $n$ is ( ).
(A) 3
(B) 6
(C) 9
(D) 12
3. B.

From the given, we have
$$
\mathrm{C}_{n}^{k}\left(x^{2}\right)^{k}\left(-\frac{1}{x}\right)^{n-k}=15 \text {. }
$$

Notice that,
$$
2 k+k-n=0 \Rightarrow k=\frac{n}{3} \Rightarrow C_{n}^{\frac{n}{3}}=15 \text {. }
$$

When $n=3$, $\mathrm{C}_{3}^{1}=3 \neq 15$;
When $n=6$, $C_{6}^{2}=15$.