ORA-00933 帮助:SQL 命令未正确结束

发布于 2024-11-04 00:47:19 字数 724 浏览 0 评论 0原文

如果我使用 Oracle 的 SQL Developer 运行以下 SQL。

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  

它工作正常,但是当我尝试使用 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;');

我收到“ORA-00933:SQL 命令未正确结束”错误消息

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 message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜未央樱花落 2024-11-11 00:47:19

看DayParams后面的双括号。您的 SQL Developer SQL 中没有它。为了避免使用 StackOverflow 作为 Oracle SQL 拼写检查器,您可以:

  1. 使用 SQL 编辑器并粘贴
    查询文本
  2. 使用字符串常量并分配
    它是一个整体,而不是逐行
    线

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:

  1. Use the SQL editor and paste the
    query text there
  2. Use a string constant and assign
    it in a whole, instead of line by
    line
南七夏 2024-11-11 00:47:19

你为什么坚持用这种艰难的方式来做这件事? :)

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;

我有一个实用程序,允许您在 IDE 中选择它并将其复制到剪贴板,运行该实用程序,然后直接粘贴到 SQL Developer 查询窗口(或任何其他编辑控件)中。我还有一个相反的功能 - 您将任何查询文本选择到剪贴板中,运行该实用程序,然后将代码粘贴到 const Whatever = 之后,以创建一个完美形成的 Delphi 字符串常量,用作上面(事实上,我在清理 SQL.Add 语句以确保嵌入的引号正确后使用了它)。

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).

情归归情 2024-11-11 00:47:19

您在 Delphi 中使用哪些组件进行查询?

ORDER BY 子句字符串末尾有一个分号,这将导致此错误,具体取决于您用于查询的组件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文