This verse is interpreted by the Talmud in the midst of a broader discussion about a certain king going bad. The part that is relevant to the interpretation of this verse is excerpted below, first in the original Hebrew and followed by the English translation, with the sentences that directly interpret the verse in bold:
Rosh Hashana 4a
אמר רב יוסף ואיתימא רבי יצחק מנלן דאחמיץ מהכא ויאמר לי המלך והשגל
יושבת אצלו מאי שגל אמר רבה בר לימא משמיה דרב כלבתא אלא מעתה הא דכתיב
ועל מרא שמיא התרוממת ולמאנייא די ביתיה היתיו קדמך ואנת ורברבניך שגלתך
ולחנתך חמרא שתין בהון ואי שגל כלבתא היא כלבתא בת משתיא חמרא היא הא לא
קשיא דמלפא לה ושתייא אלא מעתה דכתיב בנות מלכים ביקרותיך נצבה שגל
לימינך בכתם אופיר ואי שגל כלבתא היא מאי קא מבשר להו נביא לישראל הכי
קאמר בשכר שחביבה תורה לישראל כשגל לעובדי כוכבים זכיתם לכתם אופיר
ואיבע"א לעולם שגל מלכתא היא ורבה בר לימא גמרא גמיר לה ואמאי קרי לה שגל
שהיתה חביבה עליו כשגל אי נמי שהושיבה במקום שגל
R. Joseph, (or, as some say, R. Isaac) said: Whence do we know that he
deteriorated? From here: And the king said unto me, the shegal also
sitting by him. What is ‘shegal’? Rabbah b. Lema said In the name of
Rab, a she-dog. But if that is so, what are we to make of the verse,
But hast lifted up thyself against the Lord of heaven, and they have
brought the vessels of His house before thee, and thou and thy lords,
thy shegaloth and thy concubines have drunk wine in them. Now how can
‘shegal’ here be a dog? Do dogs drink wine? — This is no difficulty,
as [we can suppose that] it was taught to drink. But what of the
verse where it is written, Kings’ daughters are among thy favourites,
at thy right hand doth stand the shegal in gold of Ophir? Now if
‘shegal’ is a dog, what promise is the prophet bringing to Israel? —
What he means is this: Because the Torah is as dear to Israel as a
‘shegal’ to the heathens, you have earned as your reward the gold of
Ophir. Alternatively I may say that ‘shegal’ does as a rule mean
‘queen’, but in this case Rabbah b. Lema had a tradition [that it
means ‘dog’], and the reason why [in the text] it is called ‘shegal’
is because it was as dear to him as a queen; or, possibly, because he
put it on the queen's seat. (Soncino translation)
Similarly, the Aramaic translation (Targum) translates the word "shegal" as Oraisa (אורייתא) which is the Aramaic word for Torah.