12. If the real number $a$ satisfies
$$
a^{3}+a^{2}-3 a+2=\frac{3}{a}-\frac{1}{a^{2}}-\frac{1}{a^{3}} \text {, }
$$

then $a+\frac{1}{a}=$
12.2 or -3.

Let $a+\frac{1}{a}=b$. Then $a^{2}+\frac{1}{a^{2}}=b^{2}-2$.
$$
\begin{array}{l}
\text { Also } a^{3}+\frac{1}{a^{3}}=\left(a+\frac{1}{a}\right)\left(a^{2}+\frac{1}{a^{2}}\right)-\left(a+\frac{1}{a}\right) \\
=b\left(b^{2}-2\right)-b=b^{3}-3 b .
\end{array}
$$

According to the problem,
$$
\begin{array}{l}
\left(a^{3}+\frac{1}{a^{3}}\right)+\left(a^{2}+\frac{1}{a^{2}}\right)-3\left(a+\frac{1}{a}\right)+2=0 \\
\Rightarrow b^{3}-3 b+b^{2}-2-3 b+2=0 \\
\Rightarrow b^{3}+b^{2}-6 b=0
\end{array}
$$
$\Rightarrow b=2$ or $b=-3(b=0$ is discarded $)$.
Therefore, $a+\frac{1}{a}=2$ or -3.