【问题标题】:Attribute names in table in the form varchar2表格中的属性名称 varchar2
【发布时间】:2017-02-03 07:24:56
【问题描述】:
嘿,我正在研究面向对象的数据库,我遇到了这个问题,'用户将输入属性名称 (X) 的名称和属性的值 (Y),您必须执行以下操作...select * from table where X = Y
如何做到这一点?
【问题讨论】:
标签:
select
plsql
attributes
oracle-sqldeveloper
【解决方案1】:
从 sqlplus 你可以做一个简单的&
SQL> select * from table where x='&y' ;
Enter value for y: 12
old 1: select * from table where x='&y'
old 1: select * from table where x='12'
....
如果你想要它在 plsql 中,那么这里是如何bind variables:
-- declare variable
VARIABLE y varchar2(10);
-- assign its value
begin
:y := 'Y';
end;
/
-- use it in your procedure
declare
v_r number :=0;
begin
select count(1) from "table" where x like ('%'||:y||'%');
dbms_output.put_line('found:'||v_r);
-- you can also change bind variable value
:y := :y||':'||v_r;
end;
/
-- print value
print y
从 sqlplus 中的脚本文件启动(带@):
PL/SQL procedure successfully completed.
found:1
PL/SQL procedure successfully completed.
Q:1