It has two uses. One is, in the OED’s terms, ‘to call attention to what is about to be said’ and the earliest citation in this sense used is from Francis Beaumont’s play ‘The Knight of the Burning Pestle’, dated 1613. It was much used in comedy acts in the 20th century to introduce a joke, particularly in a double act. For example:
FUNNY MAN: ‘I say, I say, I say, my wife’s gone to the West Indies.’
STRAIGHT MAN: Jamaica?
FUNNY MAN: No, she went of her own accord
The other use is ‘as a mere exclamation expressive of surprise, delight, dismay, or indignant protest’ and one of the OED’s earliest citations in this sense is from 1890: ‘I say! won't it be glorious?’ ‘Oh, I say’ was a favourite expression of the British tennis commentator Dan Maskell (1908-1992), who would utter it when witnessing something outstanding on the court.
The first use is still current in the UK, the second perhaps rather less so.