使用一个函数插入一个值,并将该值与表中的列进行比较并返回结果 [英] Insert a value using one function and compare that value with column in a table and return result

查看:94
本文介绍了使用一个函数插入一个值,并将该值与表中的列进行比较并返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一张桌子如下。

Hi i have one table as follows.

sno	name
1	george
2	michael
3	sturridge
4	bellamy
5	oliver kahn
6	torres
7	van persie
8	saurez
9	podolski



现在我必须插入一个值并通过创建函数将该值传递给一个表。然后我必须将新插入的值与上表中的name列进行比较。如果两者都匹配,它应该显示结果为成功,否则失败。



哪种方法最好?


Now i have to insert a value and pass that value to one table by creating function. and then i have to Compare the newly inserted value with the name column in the above table. If both matches it should display the result as success,else fail.

Which is the best way to do this?

推荐答案

您是在谈论两个数据库表,当值插入一个时,请对另一个表进行检查吗?如果是这样的话,



1.你可以在第一张表的插页上创建一个触发器。在其中,检查另一个表中是否存在该值,如果是,则返回
,继续插入和打印成功消息。

否则取消操作并打印失败消息



2.你也可以写一个用户定义的函数给这个



请详细说明以便提供解决方案。
Are you talking about two database tables, and when value is getting inserted in one, do a check against another table? If that is the case,

1. you could create a trigger on first table's insert. In it, check if the value exists in the other table and
if yes, continue with insert and print success message.
else cancel the operation and print failure message

2. You can also write a user defined function to this

Please specify more details to be able to give a solution.


这篇关于使用一个函数插入一个值,并将该值与表中的列进行比较并返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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