Dream in Islām
In Islām, dreams are considered a part of prophecy and can be means of guidance or warning. Good dreams are from Allah, it is considered a blessings and a source of guidance.
What to say when you wake from a good dream:
Having good dream is a blessings from Allah, whenever you wake from a good dream you'll say "Alḥamdulillahi ʿalā kulli ḥāl" "Praise be to Allah in all circumstances/in every situation". Then make ablution and pray to Almighty Allah for your dream to come true.
May your dream be filled with positivities and blessings
When Having a Nightmare
Immediately you wake up, consider splitting over your left side shoulder 3x, then say "Aʿūdhu bi kalmātil lahit tāmāt min gaḍabihi, wa ʿiqābihi, wa sharri ʿibādihi, wa min hamazatish shayṭān wa ʿan yaḥḍurūnī" "I seek refuge in the Perfect Words of Allah from His anger and His punishment, from the evil of His slaves and from the taunts of devils and from their presence."
Remember, nightmare can be distressing, but seeking Allah's protection and calmness will help.