PRAGMA SERIALLY_REUSABLE en PL/SQL

Conoce PRAGMA SERIALLY_REUSABLE en PL/SQL: convierte variables de paquete en temporales para reducir memoria y evitar estado global en entornos multiusuario.

26 ago 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

PRAGMA SERIALLY_REUSABLE en PL/SQL

PRAGMA SERIALLY_REUSABLE es una directiva del compilador PL/SQL que indica que el estado de las variables de paquete debe existir solo durante la ejecución de una llamada concreta. A diferencia de los paquetes normales cuya memoria persiste durante toda la sesión de usuario, los paquetes marcados como serially reusable tienen su memoria asignada durante la llamada y liberada automáticamente al terminar, lo que optimiza el uso de memoria en entornos con muchos usuarios concurrentes.

Analogía del pizarrón: imagina un pizarrón en un aula. Durante la clase se escriben notas que sirven mientras dura la lección. Al finalizar la clase el pizarrón se borra y la siguiente clase comienza con el pizarrón en blanco. PRAGMA SERIALLY_REUSABLE funciona de forma equivalente: la memoria es temporal y se restablece entre llamadas.

Ejemplo simplificado de paquete con comportamiento serially reusable: CREATE OR REPLACE PACKAGE temp_pkg PRAGMA SERIALLY_REUSABLE AS g_message VARCHAR2(100) := INITIAL; PROCEDURE set_message(p_msg VARCHAR2); PROCEDURE show_message; END temp_pkg; CREATE OR REPLACE PACKAGE BODY temp_pkg PRAGMA SERIALLY_REUSABLE AS PROCEDURE set_message(p_msg VARCHAR2) IS BEGIN g_message := p_msg; END; PROCEDURE show_message IS BEGIN DBMS_OUTPUT.PUT_LINE(Message = || g_message); END; END temp_pkg;

Ejecutando el paquete en dos bloques sucesivos: en el primer bloque se llama a set_message con Hola y luego a show_message y se muestra Message = Hola. Al terminar ese bloque Oracle libera la memoria asociada al paquete. En el segundo bloque, al invocar show_message de nuevo, la variable g_message está en su valor por defecto INITIAL demostrando que el estado no persiste entre llamadas.

Cuándo usar PRAGMA SERIALLY_REUSABLE: cuando las variables de paquete son temporales y no deben persistir entre llamadas; para reducir el consumo de memoria en sistemas con miles de sesiones; para contadores de corto recorrido, registros temporales y caches pequeños que solo se usan dentro de una transacción o llamada.

Ventajas: reducción de consumo de memoria, prevención de acumulación de estado de sesión no utilizado, comportamiento determinista de inicio de estado en cada llamada y menor impacto en la gestión de recursos en entornos multiusuario. Consideraciones: no es apropiado cuando se necesita mantener estado entre llamadas dentro de la sesión, por ejemplo para cache de larga duración o datos de sesión persistentes.

Resumen práctico: PRAGMA SERIALLY_REUSABLE convierte el estado de paquete en temporal, asigna memoria solo durante la llamada, la libera al finalizar, evita bloat de memoria en sistemas concurrentes, reinicia variables con sus valores por defecto en cada ejecución y es ideal para operaciones efímeras y contadores temporales.

Sobre Q2BSTUDIO: Q2BSTUDIO es una empresa de desarrollo de software y aplicaciones a medida especializada en inteligencia artificial, ciberseguridad y soluciones cloud. Ofrecemos software a medida, aplicaciones a medida, servicios cloud aws y azure, servicios inteligencia de negocio, soluciones de inteligencia artificial e ia para empresas, agentes IA y desarrollos con power bi. Nuestro equipo integra buenas prácticas de PL/SQL y optimización de memoria con arquitecturas modernas en la nube para construir sistemas escalables y seguros.

Servicios destacados de Q2BSTUDIO: desarrollo de software a medida para empresas de todos los sectores; integración de modelos de inteligencia artificial y agentes IA; soluciones de ciberseguridad y protección de datos; migraciones y despliegues en servicios cloud aws y azure; soluciones de inteligencia de negocio y reporting con power bi; consultoría de ia para empresas y optimización de rendimiento de bases de datos PL/SQL incluyendo uso de PRAGMA SERIALLY_REUSABLE cuando corresponde.

Si buscas optimizar tus sistemas PL/SQL y reducir consumo de memoria, o desarrollar aplicaciones a medida con capacidades de inteligencia artificial y ciberseguridad, Q2BSTUDIO puede ayudarte a diseñar la mejor solución técnica y de negocio, integrando servicios cloud aws y azure, power bi y estrategias de inteligencia de negocio para maximizar valor y rendimiento.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat