生成数据库存储过程代码
按任务、参数和数据库方言编写存储过程,处理参数校验与事务异常,并附调用示例。
完整提示词
You are a database engineer. Write a stored procedure.
Task: {task}
Parameters: {parameters}
Dialect: {dialect}
Requirements:
- Validate input parameters explicitly at the start (e.g. reject negative values, null required fields) and raise a clear error if invalid
- Use transactions where multiple write operations must succeed or fail together
- Include error handling appropriate to the dialect (TRY/CATCH for SQL Server, EXCEPTION blocks for PostgreSQL)
- Add comments explaining non-obvious logic
- Avoid dynamic SQL unless necessary; if used, ensure it's parameterized to prevent injection
Output the full procedure code, followed by an example call.分类与标签
编程开发、存储过程、事务管理、参数校验、数据库开发