If I run the following SQL using Oracle's SQL Developer.
select payee_id, to_char(check_date,'d') as DOW,
(cmcl_bank_cleared - check_date) as DateDiff from AP_Master
where (cmcl_bank_cleared is not null) AND ((cmcl_bank_cleared - check_date) >=1)
order by payee_address_zip, DOW, DateDiff
It works fine, however when I try to do it using Delphi
SQL.Add('select payee_id, to_char(check_date, ' + QuotedStr('d') + ') as DOW, ');
SQL.Add('(cmcl_bank_cleared - check_date) as DateDiff from AP_Master ');
SQL.Add('where (cmcl_bank_cleared is not null) AND ((cmcl_bank_cleared - check_date) >=:DaysParam))');
SQL.Add('order by payee_id, DOW, DateDiff;');
I get the "ORA-00933: SQL Command nor properly ended" error mes开发者_开发技巧sage
Look at the double bracket after DayParams. You don't have it in your SQL Developer SQL. To avoid you to use StackOverflow as an Oracle SQL spell checker, you could:
- Use the SQL editor and paste the query text there
- Use a string constant and assign it in a whole, instead of line by line
Why do you insist on doing this the hard way? :)
const
SQLText = 'select payee_id, to_char(check_date, ''d'') as DOW,'#13 +
'(cmcl_bank_cleared - check_date) as DateDiff from AP_Master'#13 +
'where (cmcl_bank_cleared is not null)'#13 +
'AND (cmcl_bank_cleared - check_date >=:DaysParam)'#13 +
'order by payee_id, DOW, DateDiff'#13;
begin
MyQuery.SQL.Text := SQLText;
MyQuery.ParamByName('DaysParam').AsInteger := SomeNumberOfDays;
try
MyQuery.Open;
// Use query results
finally
MyQuery.Free;
end;
end;
I have a utility that will allow you to select this in the IDE and copy it to the clipboard, run the utility, and then paste directly into your SQL Developer query window (or any other edit control). I also have one that does the reverse - you select any query text into the clipboard, run the utility, and then paste the code after the const Whatever =
to make a perfectly formed Delphi string constant to use as above (in fact, I used it after cleaning up your SQL.Add statements to make sure embedded quotes were correct).
What components are you using in Delphi for your query?
You've got a semi-colon at the end of your ORDER BY clause string which will cause this error, depending on what components you are using for the query.
精彩评论