• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: In Oracle SQL, how can I create table with a rule for one value to default to a percentage of another value in the same row upon insert?

Resolved: In Oracle SQL, how can I create table with a rule for one value to default to a percentage of another value in the same row upon insert?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

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?

Answer:

You can not create table with a default value of another column

Restrictions on Default Column Values Default column values are subject to the following restrictions:


A DEFAULT expression cannot contain references to PL/SQL functions or to other columns, the pseudocolumns LEVEL, PRIOR, and ROWNUM, or date constants that are not fully specified.


The expression can be of any form except a scalar subquery expression.


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.

If you have better answer, please add a comment about this, thank you!

oracle oracle19c
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why is NGINX’s $request_uri empty?

24/03/2023

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.