Algebraic Hartog's lemma reduce to the affine case In the book algebraic geometry I of Torsten Wedhorn theorem 6.45
Let $X$ be a locally noetherian normal scheme, and let $U\subseteq X$ be an open subset with $\operatorname{codim}_X(X-U)\ge2$. Then the restriction map $\Gamma(X,O_X)\rightarrow\Gamma(U,O_X)$ is an isomorphism. In other words:every function $f\in\Gamma(U,O_X)$ on $U$ extends uniquely to $X$.
Locally noetherian means that noetherian but we do not need quasi-compact .
Question: I do not know why can we reduce to the affine case. Can there exist some affine open subscheme $\operatorname{Spec}A$ such that the intersection of $\operatorname{Spec}A$ and $U$ is empty?($U$ is the open subscheme in the theorem)
Could some one give an answer? Thank you.
 A: If $U$ is an open subset such that the codimension of $X-U$ is greater or equal to 2. Then by defition of codimension, $\min\{\dim \mathcal{O}_{X,x}:x\in X-U\}\geq 2$, i.e. points of $X-U$ are all of codimension $\geq 2$. Thus the points of codimension $0$ and $1$ lie in $U$.
It's easy to see that a point is of codimension 0 if and only if it is a generic point of $X$. So $U$ contains all generic points, its closure must be $X$, so $U$ is open dense.
Now we can safely pick any non-empty open affine subset to consider the restriction of our desired isomorphism.
Pick an affine open covering $\{U_i\}_{i\in I} $ of $X$, assuming we have isormophisms $\Gamma(U_i,\mathcal{O}_X)\to \Gamma(U_i \cap U,\mathcal{O}_X)$, we now try to deduce the isomorphism $\Gamma(X,\mathcal{O}_X)\to \Gamma(U,\mathcal{O}_X)$ from the sheaf properties, the exact sequence of sheaves.
It's easy to see that the isomorphism follows from the isomorphisms $\Gamma(U_i\cap U_j,\mathcal{O}_X)\to \Gamma(U_i \cap U_j \cap U,\mathcal{O}_X)$ for all $i$ and $j$ with a simple diagram chase. But $U_i \cap U_j$ is not necessarily affine.
Nevertheless it can be shown that $U_i \cap U_j$ can be covered by simultaneously distinguished open subsets of $U_i$ and $U_j$, see this question in StackExchange.
Now we just apply the same argument to $U_i \cap U_j$ with this covering, this time the intersection of two simultaneously distinguished open subsets is open affine, then we are done.
