ITPub博客

首页 > 数据库 > Oracle > NAME_IN and COPY built-in

NAME_IN and COPY built-in

原创 Oracle 作者:pan_tian 时间:2014-07-02 12:13:49 0 删除 编辑
You can reference items indirectly with the NAME_IN and COPY built-in subprograms.
The NAME_IN function returns the contents of an indicated variable or item.  Use the NAME_IN function to get the value of an item without referring to the item directly.
The following statements are equivalent:

IF :emp.ename = \'smith\' -- direct reference
IF NAME_IN(\'emp.ename\') = \'smith\' -- indirect reference

The return value is always a character string.  To use NAME_IN for a DATE or NUMBER item, convert the string to the desired data type with the appropriate conversion function:

date_var := TO_DATE(Name_In(\'order.date_item\'));
num_var := TO_NUMBER(Name_In(\'order.number_item\'));

Notes on NAME_IN:

*The NAME_IN function cannot return the contents of a global or local variable.

*In PL/SQL triggers that will be executed in enter-query mode, you must use NAME_IN rather than normalbind-variable notation to access values in the data-block.  (This is because the end-user might  type relational operators into the item, producing a value which is not in a form that can be processed by PL/SQL.)

The COPY Procedure  The COPY procedure assigns an indicated value to an indicated variable or item.  Unlike standard PL/SQL assignment, however, using the COPY procedure allows you to indirectly reference the item whose value is being set:

:emp.ename := \'smith\';     -- direct reference
Copy(\'smith\',\'emp.ename\');     -- indirect reference


COPY can be used with the NAME_IN function to assign a value to an item whose name is stored in a reference variable or item:

/* put value \'smith\' in item whose name is stored in ref_item */
Copy(\'smith\',Name_In(\'control.ref_item\'));

Why Use Indirect Reference  Referencing items indirectly allows you to write more generic, reusable code.  By using variables in place of actual item names, you can write a subprogram that can operate on any item whose name has been assigned to the indicated variable.
Also, using indirect reference is mandatory when you refer to the value of a form bind variable (item, parameter, global variable) in PL/SQL that you write in a library or a menu module.Because libraries, menus, and forms are separate application modules, you cannot refer directly to the value of a form item in a menu-item command or library procedure.  

library is not saved within form. but in different file, so there is no where to find :frm1.txt1

for example, if you have a procedure in library:

procedure p1( v_one varchar2)

name_in(v_one)   to get the value inside v_one, that is :frm1.txt1, so:

copy(\'value\', name_in(v_one))        ==> to copy value to the txt field txt1 in form frm1.

you can\'t use:

copy(\'value\', :frm1.txt1), nor you can:

copy(\'value\', v_one).


<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26687597/viewspace-1203617/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Select for update, nowait, skip locked
下一篇: 如何解数据库锁
请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2012-02-18

最新文章