I was asked by one of teachers to find a probability space $(\Omega,\mathcal{F},\mu)$ and a real valued integrable function $f$ on this space which is unbounded.
I gave it a try but I think I am missing something.
I took $\Omega$ to be $(0,1)$ and the sigma field to be the power set of $(0,1)$ and took the probability measure $\mu$ to be the law of Uniform$(0,1)$ random variable $X$ . Now if I construct $f(x)=p$ if $x=\frac{p}{q}$ and $f(x)=x$ if $x$ is irrational , then does the integral $f(x)$ exists but is unbounded? I am confused about the existence of the integral. Anyone with an easier example?
Two question about the detail of your function:
First:
I think you mean to assume that $\frac p q$ is a reduced fraction, right?
Second: Your choice of $\sigma$-algebra seems to be incompatible with your choice of probability measure. You won't lose anything by restricting your $\sigma$-algebra down to just the Borel $\sigma$-algebra on $(0, 1)$. Without this change, you can run into technical issues regarding being able to coherently specify a probability such as the Banach-Tarski paradox. Generally, it's advisable to choose the smallest $\sigma$-algebra that will do the job you want; here, that's the Borel $\sigma$-algebra on $(0, 1)$.
Assuming you're OK with those two adjustments: your example works fine. Your function is equal to $x$ on almost all numbers in $(0, 1)$, so its integral is equal to $\int_0^1 x \, \textrm d x$. And yet, on the set (of measure 0) for which it's different, it occasionally gets very large, as desired.
For a potentially easier example: use the same measure space as above, but just choose your favorite function from calculus that has both $\lim_{x \to 0^+} f(x) = \infty$ and a finite integral; $f(x) = 1/\sqrt x$ would work, for instance.