简体   繁体   English

Oracle Apex:如何告诉Apex使用另一个表的列中的值?

[英]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. 我们正在使用Apex GUI来建立数据库。 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. 例如,我有一个表“ customer”,其中的“ member”列下表示是或否。

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." 我希望每当为表“ order”输入新的数据行时,也具有“ member”列的表“ order”会自动从表“ customer”的“ member”列中获取值。

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 ); COMMAND table1 s(无论是哪种命令);

I have no idea what the "s" is for. 我不知道“ s”是什么意思。 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. 我已经介绍过MySQL,但是它显然与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: 假设order表包含一个customer_id列或标识该客户的类似内容,则您将创建一个插入前,逐行触发器,其中包含如下语句:

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. 假设您将构建一个Apex应用程序来输入订单,另一种方法是让相关页面在加载时(可能是隐藏的页面项中)从customer那里查询必要的信息,然后将其包含在insert语句中。

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. 同样,如果您不知道如何执行此操作,则如果打算使用Apex完成任何有用的操作,则需要做一些研究。

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. 由于member只有两个值,因此许多客户将具有相同的值,因此它不是唯一字段。

A foreign key would be appropriate for the field in order that identifies the specific customer, however. 但是,外键适用于该字段, order标识特定的客户。

You need Master-Detail page. 您需要主从页面。 Press Create page -> Form -> Master Detail Form , then choose: Create page -> Form -> Master Detail Form ,然后选择:

  • Step Master Table and Columns : Table/View name - customer , Select Columns - choose desired columns of table customer that user will edit. 步骤Master Table and ColumnsTable/View name - customerSelect Columns -选择用户要编辑的表customer所需的列。
  • Step Detail Table and Columns : Table / View Name - order , Select Columns - choose desired columns of table order . 步骤Detail Table and ColumnsTable / View Name - orderSelect Columns -选择所需的表order列。
  • Step Define Primary Key : choose primary key for both tables (or use option Managed by ROWID ) 步骤Define Primary Key :为两个表选择主键(或使用选项Managed by ROWID
  • Step Primary Key - I recommend to use previously created sequence (go to Object Browser ). 步骤Primary Key -我建议使用先前创建的序列(转到“ 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. 一页允许用户更改表customer数据,第二页允许按表order更改数据,并且该数据将自动与表customer链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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