The Shulchan Aruch · Orach Chayim
אורח חיים צ״בOrach Chayim 92
Siman 92 of 697 in Orach Chayim — 10 se'ifim
הלכות תפילהLaws of Prayer· siman 92
Se’if 1א׳
הָיָה צָרִיךְ לִנְקָבָיו, אַל יִתְפַּלֵּל. וְאִם הִתְפַּלֵּל, תְּפִלָּתוֹ תּוֹעֵבָה, וְצָרִיךְ לַחֲזֹר וּלְהִתְפַּלֵּל. וְהָנֵי מִילֵי שֶׁאֵינוֹ יָכוֹל לְהַעֲמִיד עַצְמוֹ שִׁעוּר הִלּוּךְ פַּרְסָה, אֲבָל אִם יָכוֹל לְהַעֲמִיד עַצְמוֹ שִׁעוּר פַּרְסָה, יָצָא בְּדִיעֲבַד. אֲבָל לְכַתְּחִלָּה לֹא יִתְפַּלֵּל, עַד שֶׁיִּבְדֹּק עַצְמוֹ תְּחִלָּה יָפֶה: הַגָּה: וְכָל הַנִּצְרָךְ לִנְקָבָיו אָסוּר אֲפִלּוּ בְּדִבְרֵי תּוֹרָה, כָּל זְמַן שֶׁגּוּפוֹ מְשֻׁקָּץ מִן הַנְּקָבִים (הַגָּהוֹת מַיְמוֹנִי פֶּרֶק ד' מֵהִלְכוֹת תְּפִלָּה).
One who Needs to Relieve Themselves and the Laws of Washing for Prayer, and Other Preparations for Prayer - containing 10 s'ifim. One who needs to relieve themselves should not pray, and if they prayed, their prayer is an abomination and they need to go back and pray again. And these things said are [regarding the case] of one who is not able to hold themselves back [without using the toilet] for the amount of time it takes to walk a parasang, but if one is able to hold themselves back for the amount of time of a parasang [and prays], they have fulfilled their obligation [to pray the Amidah] after the fact. But from the outset, one should not pray until they have checked themselves well beforehand. Rem"a: And anyone who needs to relieve themselves is forbidden even from [engaging in] matters of Torah as long as their body is filthy from their waste. (Hagahot Maimoni, Chapter 4 on the Laws of Prayer)
Se’if 2ב׳
אִם בְּאֶמְצַע תְּפִלָּתוֹ נִתְעוֹרֵר לוֹ תַּאֲוָה, יַעֲמִיד עַצְמוֹ עַד שֶׁיִּגְמֹר, וְלֹא יַפְסִיק. וְאִם בִּשְׁעַת קְרִיאַת שְׁמַע וּבִרְכוֹתֶיהָ נִתְעוֹרֵר בֵּין לִקְטַנִּים בֵּין לִגְדוֹלִים, קוֹרֵא כְּדַרְכּוֹ: הַגָּה: וְדַוְקָא שֶׁאֵינוֹ מִתְאַוֶּה כָּל כָּךְ דְּאִית בֵּיהּ מִשּׁוּם בַּל תְּשַׁקְּצוּ, אֲבָל בְּלָאו הָכֵי יוֹתֵר טוֹב לְהַפְסִיק (תְּשׁוּבַת הָרַשְׁבָּ"א סִימָן קל"א פָּסַק דְּמֻתָּר וּתְרוּמַת הַדֶּשֶׁן סִימָן ט"ז פָּסַק דְּאָסוּר וְצָרִיךְ לְחַלֵּק כֵּן) וְאִם רָצָה לְהַרְחִיק וּלְהָטִיל מַיִם, עוֹשֶׂה.
If, while in the middle of one's prayer [i.e. Amidah], he feels an urge [to relieve himself], he should maintain himself [in prayer] until he has finished, and not interrupt. And if at the time of the Recitation of the Sh'ma and its blessings he feels an urge, regardless of whether it is for urinating or defecating, he may read it normally. Rem"a: And [this is] specifically if one does not feel so much of a urge that there is an element of "Do not cause an abomination" (Leviticus 20:25). But if this is not so, it is better to interrupt [one's prayer and use the toilet] (Responsum of the Rashb"a, section 131, who ruled that it is permissible, and the Terumat haDeshen section 16, who ruled that it is prohibited. And one needs to distinguish such [i.e. between those sources]) And if one wanted to distance himself and urinate [during the Recitation of the Sh'ma and its blessings], he may.
Se’if 3ג׳
צָרִיךְ קֹדֶם תְּפִלָּה לְהָסִיר כִּיחוֹ וְנִיעוֹ וְכָל דָּבָר הַטּוֹרְדוֹ.
One needs, before the prayer [i.e. the Amidah], to rid himself of his mucus and phlegm and anything which [might] distract him.
Shulchan Aruch, Orach Chayim — Torat Emet 363 edition, via Sefaria — public domain
English: Sefaria Community Translation — CC0