oracle forms builder pl/sql - access a column that is dervied from other columns

我们两清 提交于 2019-12-12 02:09:17

问题


I have a view in my database that has a bunch of fields derived from other information in the database, this is how the view is defined:

create view patient_account_view AS 
  select patient.p_mrn,
         p_fname,
         p_lname,
         ammount_paid,
         quantity*item_cost + repeats*item_cost  "ammount_owing", 
         (quantity*item_cost + repeats*item_cost) - ammount_paid "balance"
    from patient_account,
         patient,
         diagnosis,
         prescribed_treatment,
         items_used,
         item,
         perscription
    where patient.p_mrn = diagnosis.p_mrn AND
          patient_account.p_mrn = patient.p_mrn AND
          diagnosis.prescribed_treatment_id = prescribed_treatment.prescribed_treatment_id AND 
          prescribed_treatment.prescribed_treatment_id = perscription.prescribed_treatment_id AND
          items_used.ptreatment_id = prescribed_treatment.prescribed_treatment_id AND
          items_used.item_number = item.item_number;

I would like to use pl/sql to access the information in the view to stick it into a form, but I'm getting a 'bad bind variable' error. How do I access this kind of attribute without having to recalculate the information stored there?

Here is the plsql that is problematic:

DECLARE
    pmrn patient.p_mrn%TYPE;
    var_ptuple patient%ROWTYPE;
    var_accttuple patient_account%ROWTYPE;
BEGIN
    pmrn := :PATIENT_BLOCK.MRN_FIELD;
    SELECT * INTO var_ptuple from patient WHERE patient.p_mrn = pmrn;
    SELECT * INTO var_accttuple from patient_account_view WHERE patient_account_view.p_mrn = pmrn;
    :PATIENT_BLOCK.FNAME := var_ptuple.p_fname;
    :PATIENT_BLOCK.LNAME := var_ptuple.p_lname;
    :PATIENT_BLOCK.BALACNCE_OWING := var_accttuple.balance;
END;

回答1:


The columns of your view patient_account_view do not match exactly the columns of the table patient_account, but in your code you have:

var_accttuple patient_account%ROWTYPE;

which means when you run this:

SELECT * INTO var_accttuple from patient_account_view ...

You haven't specified which columns get mapped to which record attributes, so Oracle requires that the column list matches exactly.

In this case, I'd expect you probably want to change the definition of the variable, e.g.

var_accttuple patient_account_view%ROWTYPE;

Side note

Since you're only using one attribute from the view, you can simplify your code as follows:

SELECT balance INTO :PATIENT_BLOCK.BALACNCE_OWING
from patient_account_view WHERE patient_account_view.p_mrn = pmrn;

and you no longer need var_accttuple.



来源:https://stackoverflow.com/questions/17891873/oracle-forms-builder-pl-sql-access-a-column-that-is-dervied-from-other-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!