简体   繁体   中英

Oracle Apex: How do I tell Apex to use the value from a column of another table?

FIRST, we are not using code. We are using the Apex GUI to set up the database. I need the column of one table to take the value from the column of another table. If it's a Trigger that I have to create, then it will probably require the code.

For example, I have a table "customer" in which there is indicated under the "member" column a yes or no.

I want the table "order" that also has a "member" column automatically take the value from the table "customer"'s "member" column whenever a new row of data is input for the table "order."

Do I do that under "constraints," because when I try to create a foreign key of the member column, it keeps giving me an error.

Do I do that under "Triggers?"

Please understand, I do not understand the code very well. When someone says something like

COMMAND table1 s ( Whatever comands );

I have no idea what the "s" is for. And I'm pretty sure there's a lot of other stuff I don't quite understand either. I have been introduced to MySQL, but it apparently has some differences to Apex Oracle.

Thank you.

A trigger is one way to do it. Assuming that the order table includes a customer_id column or something similar that identified the customer, you would create a before-insert, for-each-row trigger that includes a statement like this:

SELECT customer.member INTO :new.member
FROM customer WHERE customer.customer_id = :new.customer_id

Frankly, you'll need to do some reading to learn how to write proper triggers if this is something you want to do.

Assuming you will be building an Apex application to enter orders, another approach would be to have the relevant page query the necessary information from customer when it loads (probably into hidden page items), then include them in the insert statement.

Again, if you don't know how to do this, you need to do some study if you are planning to use Apex to accomplish anything useful.

A foreign key here is not appropriate. The column referenced by the foreign key must be unique; since member has only two values, many customers will have the same value, so it is not a unique field.

A foreign key would be appropriate for the field in order that identifies the specific customer, however.

You need Master-Detail page. Press Create page -> Form -> Master Detail Form , then choose:

  • Step Master Table and Columns : Table/View name - customer , Select Columns - choose desired columns of table customer that user will edit.
  • Step Detail Table and Columns : Table / View Name - order , Select Columns - choose desired columns of table order .
  • Step Define Primary Key : choose primary key for both tables (or use option Managed by ROWID )
  • Step Primary Key - I recommend to use previously created sequence (go to Object Browser ).

In all other steps you can choose values by default. After this steps you will have two pages (or three, depending on what you choose in a wizard). One page allows user to change data in the table customer , second - to change data in the table order , and this data will be linked with the table customer automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM