CORRECTING A BRACHAH TOCH KEDEI DIBUR [Berachos: Toch Kedei Dibur]
Gemara
R. Yehoshua ben Levi (to Mashi'ach): Shalom Alecha Rebbi v'Mori!
Bava Kama 73b: There are two measures of Toch Kedei Dibur. A Rebbi greets his Talmid 'Shalom Alecha.' A Talmid greets his Rebbi 'Shalom Alecha Rebbi v'Mori'. R. Yosi holds that within the longer time (to say four words) is a continuation, but within the shorter time (to say two words) is not.
Berachos 12a: Surely, if one was holding a cup of wine, thinking that it was beer, and began to bless (sheha'Kol) for beer, and he (remembered that it is wine, and) blessed (Borei Peri ha'Gafen) for wine, he was Yotzei, for even had he said sheha'Kol, he would have been Yotzei.
Question: If one had beer, but thought that it is wine, and began to bless for wine, and he (remembered, and) blessed for beer, what is the law?
If it depends on the beginning (Borei Peri ha'Gafen), he was not Yotzei. If it depends on the end (he closed properly), he was Yotzei.
Answer #1 (Beraisa): In the morning, if one began Yotzer Or and concluded with ha'Ma'ariv Aravim, he was not Yotzei. If he began ha'Ma'ariv Aravim and concluded Yotzer Or, he was Yotzei. The general rule is, it all depends on the Chasimah (end) of the Berachah.
Rejection: Rabah bar Ula taught that the Berachos were formulated to mention the attribute of day at night, and vice-versa. Therefore, the beginning of the Berachah, which has Hash-m's name and Malchus, was proper.
Answer #2 (Beraisa): The rule is, it all depends on the Chasimah.
Suggestion: 'The rule is' comes to include our case (of beer)!
Rejection: No. He ate dates, but thought that he ate bread, and began Birkas ha'Mazon, and he blessed "Al ha'Etz." He was Yotzei, for dates also give sustenance.
Bava Basra 129b: The Halachah is, anything said within Toch Kedei Dibur is like part of the previous matter, except for idolatry and Kidushin.
Shevuos 32a (Mishnah): If both witnesses simultaneously denied knowing, they are liable.
(R. Yochanan): We need not establish this like R. Yosi ha'Galili, who says that two events can occur simultaneously. Rather, the latter denied Toch Kedei Dibur of the first, so it is like is a continuation of what the first said.
Rishonim
Rif and Rosh (Berachos 12a and 1:14): The question about fixing a Berachah was not resolved. We are lenient and he does not repeat the Berachah, for it is a Safek mid'Rabanan.
Tosfos (12a DH Lo): The Ri is stringent and says that one must bless again. R. Tam says that if he erred in his speech he was Yotzei, e.g. he knew that it is Yom Tov but said Mekadesh ha'Shabbos, and corrected himself Toch Kedei Dibur. R. Yakov asked, what was the Gemara's question? Mitzvos do not require Kavanah! The Ri answered that this refers to one who heard a Berachah without intent, but if he intended to bless on wine and it was beer, ut does not help.
Rosh (ibid.): Rashi holds that he began to bless and said Hash-m's name with the wrong intent. The Ra'avad disagrees, for we never find that a Berachah is disqualified due to a lack of intent. One is Yotzei even without any intent, and all the more so when he intended for a Berachah (even if it is the wrong one). This is not difficult. No intent is better, for wrong intent uproots it to another Berachah! However, the Gemara says 'he began Yotzer Ohr...' which connotes saying the words, and not mere intent. The Rif's text is primary. He began to bless sheha'Kol, and concluded Borei Peri ha'Gefen. He was Yotzei, for even had he not corrected himself, he would have been Yotzei.
Teshuvas ha'Rashba (1:35): Most explain like the Rif, that the question is whether one was Yotzei b'Di'eved. This is primary, even though some disagree. If (during the 10 days of Teshuvah) one said 'ha'Kel ha'Kadosh', and Toch Kedei Dibur he remembered and said 'ha'Melech ha'Kadosh', according to the Ge'onim's text in Berachos, he does not go back. Their text says that if one was holding beer, and began to bless for wine, and he blessed for beer, he was Yotzei, even though he would not have been Yotzei had he concluded for wine. He merely added praises in the middle. Also here, he was Yotzei. The Rif agrees. However, Rashi holds that we discuss one who said Hash-m's name with intent for wine, but he remembered before he mentioned wine. Had he mentioned wine, he would not be Yotzei. The same applies here. I hold that Rashi's Perush of the Gemara is better. However, we cannot rule against the Ge'onim and require another Berachah. It is better to be passive. However, if he did not correct himself within Toch Kedei Dibur, he returns to the beginning of Tefilah, for the first three Berachos are considered like one. This applies to an individual or a Shali'ach Tzibur. The Yerushalmi distinguishes them, but the Bavli does not.
Poskim
Shulchan Aruch (OC 206:3): Regarding all these Berachos, one may not interrupt between the Berachah and eating (Rema - more than Kedei Dibur).
Taz (3): This is the time for a Talmid to greet his Rebbi, 'Shalom Alecha Rebbi v'Mori.'
Kaf ha'Chayim (15): This is like the Beis Yosef citing Shibolei ha'Leket, and the Levush. Shirei Keneses ha'Gedolah says that the correct text should say the time to say three words, 'Shalom Alecha Rebbi.'
Note: Shinuy Nusch'aos in the Frankel Bava Kama/Sefer ha'Mafte'ach brings many opinions that the text on 73b includes the word 'v'Mori', and many opinions that it does not.
Magen Avraham (209:3): The Shulchan Aruch rules (regarding beer) that he was Yotzei if he knew that it is beer, but he said the wrong words. If he thought that it is wine, Tosfos and many Poskim say that he was not Yotzei. Why is Tosfos stringent? We are lenient about Safek Berachos! Perhaps he holds that Mitzvos require Kavanah. All agree that one must bless again for Birkas ha'Mazon, for it is mid'Oraisa.l
Magen Avraham (4): The Shulchan Aruch connotes that after Kedei Dibur, he must bless again. Some say that other Poskim disagree. Ri ha'Levi says that all agree. However, Tosfos implies that only the Ri says so.
Shulchan Aruch (487:1): If on Yom Tov one concluded 'Mekadesh ha'Shabbos', and retracted (to say Mekadesh Yisrael veha'Zmanim) Toch Kedei Dibur, he was Yotzei, since he knows that it is Yom Tov.
Gra (4): Tosfos is stringent if he did not know that it is Yom Tov, for R. Yochanan taught that it would be ideal to pray the entire day, so one repeats Shemoneh Esre due to Safek. The Isur of an unnecessary Berachah is only mid'Rabanan, like it says at the end of Rosh Hashanah. Bahag and others say that we are lenient about all Safek Berachos.
Magen Avraham (2): If he thought that it is Shabbos, and remembered Toch Kedei Dibur, he was not Yotzei, like I wrote above. Here the Shulchan Aruch connotes that if he concluded Mekadesh ha'Shabbos, he was not Yotzei, i.e. if he omitted Yom Tov in the middle. If he mentioned Yom Tov, he was Yotzei. One who who said a weekday Shemoneh Esre was Yotzei if he mentioned Shabbos in the middle (268:4), and all the more so here, where he concluded Mekadesh ha'Shabbos, for Yom Tov is called Shabbos. Also in Sa'if 3, we say that one was Yotzei if he said Ya'aleh v'Yavo, i.e. even if he did not end with Yom Tov. If so, if he concluded Mekadesh Yisrael veha'Zmanim he was Yotzei even if he did not mention Yom Tov in the middle. However, this is difficult. Where Chachamim enacted to close (with Baruch Atah Hash-m at the end), one must close (Berachos 11a)! Also, everything follows the ending! Also, since Chachamim fixed a special Berachah for Shabbos, how can one be Yotzei through a weekday Shemoneh Esre in which he mentioned Shabbos in the middle but did not close with Shabbos?! It is because really, one should say 18 Berachos on Shabbos, but due to Kavod Shabbos Chachamim did not obligate this.
Mishnah Berurah (4): He corrected himself within the time to say three words. If he paused longer, he returns to the start of the Berachah, since he closed improperly, even if he mentioned Yom Tov in the middle.
Mishnah Berurah (5): If when he said Baruch Atah Hash-m he thought that it is Shabbos, the Shulchan Aruch holds that he was not Yotzei. Most Poskim say that he was Yotzei. The Gra concludes like them.
Kaf ha'Chayim (11): Eshel Avraham says that if one said Mekadesh ha'Shabbos, and then remembered and said Yisrael veha'Zmanim without 'Mekadesh', he was not Yotzei, for he connotes that it is also Shabbos, but it is not. This is difficult. If one started to bless Borei Peri ha'Gefen, and Toch Kedei Dibur finished sheha'Kol Nihyeh bi'Dvaro, he was Yotzei. If one said 'ha'Kel ha'Kadosh', and Toch Kedei Dibur he remembered and said 'ha'Melech ha'Kadosh', he was Yotzei (582:2). Why is this different? Rather, he was Yotzei even though there are extra words in the middle. This is obvious according to the Poskim who say that Yom Tov is called Shabbos.
Kaf ha'Chayim (12): If one waited more than Kedei Dibur and corrected himself, he was not Yotzei. However, some say that here he is Yotzei even without correcting himself. Perhaps we can join this opinion; if he corrected himself after Kedei Dibur, it is a Safek, so he does not bless again.
Kaf ha'Chayim (13): If he started the next Berachah, he cannot correct himself even Toch Kedei Dibur.