如何在pl / sql中创建一个在过程体内部插入和删除代码的过程。 [英] How to create a procedure which have insert and delete code inside the procedure body in pl/sql.

查看:103
本文介绍了如何在pl / sql中创建一个在过程体内部插入和删除代码的过程。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的表(template_colour_t)。这两列是主键的组合。



> template_id colour_id



> ------------- | -------------



> tp0001 | 0001

> tp0001 | 0003

> tp0002 | 0002

> tp0003 | 0001



我想要一个程序,在这个程序中保持插入和更新代码。



更多信息:



Template_id'tp0001'与多个colour_id(0001 0005,0003)连接



我想用这个template_id添加和删除一些colur_id。



示例:



添加和删除后template_id'tp0001'应该有(0001,005,0004,0009,000)这么多colour_id。





在程序里面我们需要检查什么和所有exsist和什么是新的,如果任何一个不存在然后需要删除。



基于我们需要删除,插入这一行。



请帮助我获取该代码。



高级感谢所有人。

I have a table (template_colour_t) with two columns. Those two columns are combination of primery key.

> template_id colour_id

> -------------|-------------

> tp0001 | 0001
> tp0001 | 0003
> tp0002 | 0002
> tp0003 | 0001

I want a procedure which will maintain insert and update code in this single procedure.

More info:

Template_id 'tp0001' is connected with multiple colour_id (0001, 0005, 0003)

I want to add and remove some colur_id with this template_id.

Example:

After add and remove the template_id 'tp0001' should have (0001, 0005, 0004, 0009, 0008) this many colour_id.


Inside the procedure we need to check what and all exsist and what are the new one and if any one is not exist then need to delete.

Based on that we need to delete, insert the row.

Please help me to get that code.

Advanced thanks to all.

推荐答案

您可以使用IF EXISTS检查是否存在具有特定值的行



EXISTS(Transact-SQL) [ ^ ]



sql - 检查是否存在行,否则插入 - Stack Overflow [ ^ ]



或MERGE如果您的SQL版本支持它(例如也在上面的链接中)。
You can check if a row with particular values exists by using IF EXISTS

EXISTS (Transact-SQL)[^]

sql - Check if a row exists, otherwise insert - Stack Overflow[^]

Or MERGE if your version of SQL supports it (example also in link above).


这篇关于如何在pl / sql中创建一个在过程体内部插入和删除代码的过程。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆