Technique 1:
Turn it up loud enough so the energy from the speakers keeps the string exited. This sustain will last forever (as long as the amp is on).
You have to have pickups that won’t squeal by themselves from the feedback.
Compression helps control it, but you still need the above feedback effect to sustain the note forever.
You can move about and find harmonics of the fundamental frequency. Pretty cool (see Steve Vai).
Technique 2:
Simple compression. This boosts the volume of the signal as the string loses energy. Won’t last forever but you can get much longer notes. It helps to have a stiff guitar so the string loses energy at a slower rate.
Technique 3:
Drive a synth with the guitar. This is more common these days as synthesizer technologies blend with traditional effects. In this case the synth is actually making the sound, triggered by the string. A synth note can have infinite decay.
Technique 4:
Use something else to keep the string exited (put energy into the string), like an e-bow, or even an old fashioned violin bow.
I think that exhausts it...