OceanBase SQL語句的注釋

2021-06-18 10:44 更新

注釋可以使應(yīng)用程序更易于閱讀和維護(hù)。例如,您可以在語句中用注釋以描述該語句在應(yīng)用程序中的用途。除 Hint 外,SQL 語句中的注釋不會影響語句的執(zhí)行。

注釋可以出現(xiàn)在語句中的任何關(guān)鍵字、參數(shù)或標(biāo)點(diǎn)符號之間。您可以通過兩種方式在語句中添加注釋:

  • 以斜杠和星號(/*)為開頭的注釋。斜杠和星號后跟著注釋的文本。此文本可以跨越多行,并用星號和斜杠(*/)結(jié)束注釋。開頭和結(jié)尾的符號不必與文本用空格或換行符進(jìn)行分隔。
  • 以兩個連字符(--)為開頭的注釋。符號后跟著注釋的文本。此文本不能擴(kuò)展到新行,并以換行符結(jié)束注釋。

一個 SQL 語句可以同時包含這兩種風(fēng)格的多個注釋。注釋的文本可以包含數(shù)據(jù)庫字符集中的任何可打印字符。

以下示例展示了多種形式的以斜杠和星號(/*)為開頭的注釋:

SELECT last_name, employee_id, salary + NVL(commission_pct, 0), 
            job_id, e.department_id
  /* Select all employees whose compensation is
  greater than that of Pataballa.*/
  FROM employees e, departments d
  /*The DEPARTMENTS table is used to get the department name.*/
  WHERE e.department_id = d.department_id
    AND salary + NVL(commission_pct,0) >   /* Subquery:       */
       (SELECT salary + NVL(commission_pct,0)
         /* total compensation is salary + commission_pct */
         FROM employees 
         WHERE last_name = 'Pataballa')
  ORDER BY last_name, employee_id;

以下示例中的語句包含多種形式的以兩個連字符(- -)為開頭的注釋:

SELECT last_name,                                   -- select the name
       employee_id                                  -- employee id
       salary + NVL(commission_pct, 0),             -- total compensation
       job_id,                                      -- job
       e.department_id                              -- and department
  FROM employees e,                                 -- of all employees
       departments d
  WHERE e.department_id = d.department_id
    AND salary + NVL(commission_pct, 0) >           -- whose compensation 
                                                    -- is greater than
        (SELECT salary + NVL(commission_pct,0)      -- the compensation
          FROM employees 
          WHERE last_name = 'Pataballa')            -- of Pataballa
  ORDER BY last_name                                -- and order by last name
           employee_id                              -- and employee id.
;
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號