Example 19 consists of forming $n(\geqslant 3)$-digit numbers using the digits $1,2,3$, with the requirement that each of the digits $1,2,3$ must appear at least once in the $n$-digit number. Find the number of such $n$-digit numbers.
Let the set of $n$-digit numbers composed of $1, 2, 3$ be $S$, and the set of numbers that do not contain the digit $i$ be $A_{i}(i=1,2,3)$. Thus,
$$
|S|=3^{n},\left|A_{i}\right|=2^{n}(i=1,2,3),\left|A_{i} \cap A_{j}\right|=1(1 \leqslant i<j \leqslant 3),\left|A_{1} \cap A_{2} \cap A_{3}\right|=0 .
$$
$\bar{A}_{i}=S \backslash A_{i}$ represents the set of $n$-digit numbers where the digit $i$ must appear, and the set of $n$-digit numbers where the digits $1, 2, 3$ all appear at least once is $\bar{A}_{1} \cap \bar{A}_{2} \cap \bar{A}_{3}$.
By the principle of inclusion-exclusion, we get
$\left|\bar{A}_{1} \cap \bar{A}_{2} \cap \bar{A}_{3}\right|$
$$
=|S|-\left|A_{1}\right|-\left|A_{2}\right|-\left|A_{3}\right|+\left|A_{1} \cap A_{2}\right|+\left|A_{1} \cap A_{3}\right|+\left|A_{2} \cap A_{3}\right|-\mid A_{1} \cap
$$
$A_{2} \cap A_{3}$ |
$$
=3^{n}-3 \cdot 2^{n}+3 .
$$