SQL错误为什么会出现“缺少正确的括号”的问题?

时间:2019-05-10 15:17:57

标签: sql oracle

当我尝试在“缺少右括号”的“ Round((((......)”行中运行查询时,我不知道为什么。我在左边数了三个括号,并且随着代码/行的继续,请关闭所有括号。

我正在Oracle中运行它。只是处理子查询的作业问题。这是硬件问题,它是否可以帮助任何人:

  

对于每个直接持有人:列出持有人的姓名,该直接持有人投资的公司的名称,当前持有的股份数量,该持有人拥有的流通股百分比以及该持有人总数的百分比授权股份。按直接所有者的姓,名和公司名称对输出进行排序,并将百分比显示到小数点后两位。

代码:

SELECT direct_holder.first_name,
       direct_holder.last_name, 
       company.name,
       current_shareholder_shares.shares,
       ROUND(((current_shareholder_shares.shares/current_stock_stats.total_outstanding)*100, 2) AS "% Owned of Outstanding"),
       ROUND(((current_shareholder_shares.shares/current_stock_stats.current_authorized)*100, 2) AS "% Owned of Total Authorzied")

FROM direct_holder
      JOIN company ON company.company_id = direct_holder.direct_holder_id
      JOIN current_share_stats ON current_stock_stats.shock_id = company.stock_id
      JOIN current_shareholder_shares ON current_shareholder_shares.stock_id = current_shareholder_stats.stock_id
WHERE current_shareholder_shares = (SELECT type
                                    FROM current_shareholder_shares
                                    WHERE type = 'Direct_Holder')
ORDER BY direct_holder.first_name,
         direct_holder.last_name,
         company.name;

4 个答案:

答案 0 :(得分:0)

我认为您的列名的CustomDataBean应该在所有括号之外:

选择

...,

ROUND(((((current_shareholder_shares.shares / current_stock_stats.total_outstanding)* 100,2))为“拥有的未偿还百分比”,

ROUND(((((current_shareholder_shares.shares / current_stock_stats.current_authorized)* 100,2))表示为“拥有的总授权百分比”

FROM直接持有人

在哪里...

答案 1 :(得分:0)

您的括号过多。最后的那些不是必需的,因此ROUND语句中有太多:

   ROUND((current_shareholder_shares.shares/current_stock_stats.total_outstanding)*100, 2) AS "% Owned of Outstanding",
   ROUND((current_shareholder_shares.shares/current_stock_stats.current_authorized)*100, 2) AS "% Owned of Total Authorzied"

甚至太多了。数学上/和*可以按它们出现的顺序执行:

   ROUND(current_shareholder_shares.shares/current_stock_stats.total_outstanding*100, 2) AS "% Owned of Outstanding",
   ROUND(current_shareholder_shares.shares/current_stock_stats.current_authorized*100, 2) AS "% Owned of Total Authorzied"

答案 2 :(得分:0)

试试这个-

SELECT 
direct_holder.first_name,
direct_holder.last_name, 
company.name,
current_shareholder_shares.shares,
ROUND((current_shareholder_shares.shares/current_stock_stats.total_outstanding)*100, 2) AS [% Owned of Outstanding],
ROUND((current_shareholder_shares.shares/current_stock_stats.current_authorized)*100, 2) AS [% Owned of Total Authorzied]
FROM direct_holder
JOIN company 
    ON company.company_id = direct_holder.direct_holder_id
JOIN current_share_stats 
    ON current_stock_stats.shock_id = company.stock_id
JOIN current_shareholder_shares 
    ON current_shareholder_shares.stock_id = current_shareholder_stats.stock_id
WHERE current_shareholder_shares = 'Direct_Holder'
ORDER BY 
direct_holder.first_name,         
direct_holder.last_name,
company.name;

答案 3 :(得分:-1)

您可以尝试...错误地使用了ROUND

SELECT direct_holder.first_name,
       direct_holder.last_name, 
       company.name,
       current_shareholder_shares.shares,
       ROUND((current_shareholder_shares.shares/current_stock_stats.total_outstanding)*100, 2) AS "% Owned of Outstanding",
       ROUND((current_shareholder_shares.shares/current_stock_stats.current_authorized)*100, 2) AS "% Owned of Total Authorzied"

FROM direct_holder
WHERE current_shareholder_shares = (SELECT type
                                    FROM current_shareholder_shares
                                    WHERE type = 'Direct_Holder')

      JOIN company ON company.company_id = direct_holder.direct_holder_id
      JOIN current_share_stats ON current_stock_stats.shock_id = company.stock_id
      JOIN current_shareholder_shares ON current_shareholder_shares.stock_id = current_shareholder_stats.stock_id
ORDER BY direct_holder.first_name,
         direct_holder.last_name,
         company.name;