在Oracle SQL中,如何使用一个规则创建一个值以默认为一个值,以默认为插入时同一行中另一个值的百分比?
如何更改创建表格块,以使“佣金”默认为“价格”的百分比?
例如,在进行插入并输入佣金中时,是否有一种方法可以使“佣金”自动为“价格”的5%?
CREATE TABLE SALE (
price NUMBER (5, 2),
commission NUMBER (5, 2)
);
INSERT INTO SALE (price, commission)
VALUES(1000, NULL)
;
How can I change the CREATE TABLE block so that 'commission' will default to a percentage of 'price'?
For example, is there a way to have 'commission' automatically be a 5% of 'price' when doing an INSERT and entering NULL for commission?
CREATE TABLE SALE (
price NUMBER (5, 2),
commission NUMBER (5, 2)
);
INSERT INTO SALE (price, commission)
VALUES(1000, NULL)
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用另一列的默认值创建表
oracle
文档插入。但这是另一个问题。堆栈溢出的规则是在一篇文章中不问多个问题。
You can not create table with a default value of another column
ORACLE documentation
You can create a trigger for the
INSERT
. But that is another question. And Stack Overflow has a rule of not asking multiple questions in one post.