嘿,我正在研究面向对象的数据库,我遇到了这个问题,'用户将输入属性名称(X)的名称和属性(Y)的值,您必须执行以下操作...
select * from table where X = Y
怎么做到这一点?
答案 0 :(得分:0)
从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