--- title: 'PL/pgSQL While Loop' page_title: 'PostgreSQL PL/pgSQL While Loop' page_description: 'In this tutorial, you will learn how to use the PL/pgSQL while loop statement to execute a block of code as long as a condition is true.' prev_url: 'https://www.postgresqltutorial.com/postgresql-plpgsql/pl-pgsql-while-loop/' ogImage: '/postgresqltutorial/plpgsql-WHILE-loop.png' updatedOn: '2024-03-19T04:00:13+00:00' enableTableOfContents: true previousLink: title: 'PL/pgSQL Loop Statements' slug: 'postgresql-plpgsql/plpgsql-loop-statements' nextLink: title: 'PL/pgSQL For Loop' slug: 'postgresql-plpgsql/plpgsql-for-loop' --- **Summary**: in this tutorial, you will learn how to use PL/pgSQL `while` loop statement to execute statements as long as a condition is true. ## Introduction to PL/pgSQL while loop statement The `while` loop statement executes one or more statements as long as a specified condition is true. Here’s the basic syntax of a `while` loop statement: ```sql [ <