Example 6 Find the number of $n$-digit numbers formed by $1,2,3$, where each of 1, 2, and 3 must appear at least once in the $n$-digit number.
Let the set of all $n$-digit numbers composed of $1,2,3$ be denoted as the universal set $S$, then $|S|$ $=3^{n} . S$ The set of $n$-digit numbers in $S$ that do not contain $i(i=1,2,3)$ is denoted as $A_{i}$, then $\left|A_{i}\right|=2^{n}$, $\left|A_{i} \cap A_{j}\right|=1,\left|A_{1} \cap A_{2} \cap A_{3}\right|=0, i \neq j, i, j=1,2,3 . \bar{A}_{1} \cap \bar{A}_{2} \cap \bar{A}_{3}$ is the set of all $n$-digit numbers in $S$ that contain the digits $1,2,3$ simultaneously. By the principle of inclusion-exclusion, we have
$$
\begin{aligned}
\left|\bar{A}_{1} \cap \bar{A}_{2} \cap \bar{A}_{3}\right|= & |S|-\left[\left|A_{1}\right|+\left|A_{2}\right|+\left|A_{3}\right|-\left|A_{1} \cap A_{2}\right|-\mid A_{1}\right. \\
& \left.\cap A_{3}|-| A_{2} \cap A_{3}|+| A_{1} \cap A_{2} \cap A_{3} \mid\right],
\end{aligned}
$$

then $\left|\bar{A}_{1} \cap \bar{A}_{2} \cap \bar{A}_{3}\right|=3^{n}-3 \cdot 2^{n}+3$.