2011-10-13 1 views
4

델파이 7과 오라클에서 ADOQuery를 사용하고 있습니다. ADOQuery에 매개 변수를 전달하는 동안 오류가 발생합니다. 다음 라인을 사용했습니다. 오류를 식별하도록 도와주세요. 내가 쿼리를 열 때 나는 오류 다음 얻을 것이다ADOQuery 개체에 매개 변수를 전달하는 방법은 무엇입니까?

ADOQuery.Sql.text:= 'select * from temp_table '+ 
     'where column1 in (select column from table2 where id=:id) and id=:id'; 
ADOQuery.Parameters.ParamByValue('id').value= 'abc'; 
ADOQuery.open; 

:

당신은 두 개의 ID를 구별 할 필요가

Parameter object is improperly defined. Inconsistent or incomplete information is provided.

+0

마지막 쿼리 조건을 제거하면 올바르게 작동합니다. 'select * from temp_table where column1 in table2 from id = : id' – Nalu

+1

2 "id"대신에 id1과 id2를 사용하십시오 – SimaWB

답변

4

우리는 같은 문제가, 우리 종료 된 "마스킹"클래스 TParameters :

선언 :

TMyParameter = class(TParameter) 
private 
    function GetAsValue: variant; 
    Procedure SetAsValue(const Value: variant); 
public 
    property Value: variant read GetAsValue write SetAsValue; 
end; 

구현 :

procedure TMyParameter.SetAsValue(const Value: variant); 
var 
    iPar: Integer; 

begin 
    for iPar:= 0 to Collection.Count - 1 do 
    if (Name = TParameter(Collection.Items[iPar]).Name) then 
     TParameter(Collection.Items[iPar]).Value:= Value; 
end; 

function TMyParameter.GetAsValue: variant; 
begin 
    Result:= inherited Value; 
end; 

어떻게 사용하는 :

TMyParameter(ADOQuery.Parameters.ParamByName('id')).AsValue:= 'abc'; 

나는 그것이 도움이되기를 바랍니다.

0

;의 :

ADOQuery.Sql.text:= 'select * from temp_table a where column1 in (select column from table2 b where b.id=:id) and a.id=:id'; 
ADOQuery.Parameters.ParamByValue('id').value= 'abc'; 
ADOQuery.open; 
+0

각각 동일한 id를 사용할 수 있습니까? 실제로 원래 쿼리에서이 'ID'필드를 7 번 전달해야합니다. – Nalu

+0

@naren : 가능 합니다만 paramby ... 메소드는 첫 번째 메소드 만 찾습니다. 그래서 다른 두 답변이 모든 매개 변수를 반복하고 이름이 일치하는 모든 위치를 업데이트합니다. –

1
for i:=0 to ADOQuery.Parameters.Count-1 do 
begin 
    if ADOQuery.Parameters.Items[i].Name = 'id' then 
    ADOQuery.Parameters.Items[i].Value := 'abc'; 
end;