For me it was most likely the Star Trek Voyager episode where the crew was being forced to sleep by aliens and Chakotay was able to go into a lucid dream to fight them.