• <i id='z2DEn'><tr id='z2DEn'><dt id='z2DEn'><q id='z2DEn'><span id='z2DEn'><b id='z2DEn'><form id='z2DEn'><ins id='z2DEn'></ins><ul id='z2DEn'></ul><sub id='z2DEn'></sub></form><legend id='z2DEn'></legend><bdo id='z2DEn'><pre id='z2DEn'><center id='z2DEn'></center></pre></bdo></b><th id='z2DEn'></th></span></q></dt></tr></i><div id='z2DEn'><tfoot id='z2DEn'></tfoot><dl id='z2DEn'><fieldset id='z2DEn'></fieldset></dl></div>
    <legend id='z2DEn'><style id='z2DEn'><dir id='z2DEn'><q id='z2DEn'></q></dir></style></legend>

      <tfoot id='z2DEn'></tfoot>
      • <bdo id='z2DEn'></bdo><ul id='z2DEn'></ul>

      <small id='z2DEn'></small><noframes id='z2DEn'>

        查找 SQL 中引用的列名和表名

        时间:2023-11-28

            • <bdo id='mwa6c'></bdo><ul id='mwa6c'></ul>

                  <i id='mwa6c'><tr id='mwa6c'><dt id='mwa6c'><q id='mwa6c'><span id='mwa6c'><b id='mwa6c'><form id='mwa6c'><ins id='mwa6c'></ins><ul id='mwa6c'></ul><sub id='mwa6c'></sub></form><legend id='mwa6c'></legend><bdo id='mwa6c'><pre id='mwa6c'><center id='mwa6c'></center></pre></bdo></b><th id='mwa6c'></th></span></q></dt></tr></i><div id='mwa6c'><tfoot id='mwa6c'></tfoot><dl id='mwa6c'><fieldset id='mwa6c'></fieldset></dl></div>
                    <tbody id='mwa6c'></tbody>

                  <tfoot id='mwa6c'></tfoot>

                  <small id='mwa6c'></small><noframes id='mwa6c'>

                  <legend id='mwa6c'><style id='mwa6c'><dir id='mwa6c'><q id='mwa6c'></q></dir></style></legend>
                  本文介绍了查找 SQL 中引用的列名和表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何查找 SQL 中使用的所有表名和列名?它位于 ORACLE 数据库上.下面是一个 SQL 示例.

                  How to find all the tables and column names used in a SQL? It is on ORACLE database. Below is an SQL example.

                  SELECT 
                     A.ENAME,
                     A.AGE as EMP_AGE,
                     B.DNAME 
                  FROM
                     emp a,
                     dept b
                  WHERE
                     a.deptno= b.deptno
                  

                  我希望输出是这样的

                  TABLENAME, COLUMNNAME
                  EMP, ENAME
                  EMP, DEPTNO
                  EMP, AGE
                  DEPT, DNAME
                  DEPT, DEPTNO
                  

                  我做了一些研究,但未能找到完美的解决方案.如果我们创建视图或存储过程有帮助吗?请指教.

                  I did some research and failed to find a perfect solution. does it help if we create a view or stored procedure? Please advise.

                  推荐答案

                  我有一个很好的解决方案,但你需要做两件事:

                  I have a great solution for you, but there are two things you will need to do:

                  1. 将 SQL 放在 PL/SQL 程序单元中.所以,是的,你提到的存储过程.

                  1. Place the SQL inside a PL/SQL program unit. So, yes, to the stored procedure you mentioned.

                  在 12.2 实例上编译该程序单元和所有相关表(即安装您的应用程序代码)(您可以在 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html 或者您可以购买访问 cloud.oracle.com 的 Exadata Express CLoud 服务,或访问 cloud.oracle.com/tryit 获得 300 美元的信用额度,免费使用一个月).

                  Compile that program unit and all dependent tables (that is, install your application code) on a 12.2 instance (you can download 12.2 at http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html or you can purchase an Exadata Express CLoud Service at cloud.oracle.com or get a $300 credit to use one at no cost for a month at cloud.oracle.com/tryit).

                  12.2 是关键,因为您真正想要使用的功能称为 PL/Scope,它是一个编译器工具,用于收集有关 PL/SQL 标识符(从 11.1 开始)和 PL/'SQL(从 12.2 开始)中的 SQL 使用情况的信息).

                  12.2 is key because the feature you REALLY want to use is called PL/Scope and it is a compiler tool that collections information about PL/SQL identifiers (as of 11.1) and SQL usage inside PL/'SQL (as of 12.2).

                  CREATE TABLE my_data (n NUMBER)
                  /
                  
                  ALTER SESSION SET plscope_settings='identifiers:all, statements:all'
                  /
                  
                  CREATE OR REPLACE PROCEDURE my_procedure (n_in IN NUMBER)
                     AUTHID DEFINER
                  IS
                     l_n           my_data.n%TYPE;
                  
                     CURSOR all_data_cur
                     IS
                            SELECT *
                              FROM my_data
                        FOR UPDATE OF n;
                  BEGIN
                     INSERT INTO my_data (n)
                          VALUES (n_in);
                  
                  END;
                  /
                  
                    SELECT idt.line,
                           idt.owner || '.' || idt.object_name code_unit, 
                           idt.name column_name,
                           RTRIM (src.text, CHR (10)) text
                      FROM all_identifiers idt, all_source src
                     WHERE     idt.usage = 'REFERENCE'
                           AND idt.TYPE = 'COLUMN'
                           AND idt.line = src.line
                           AND idt.object_name = src.name
                           AND idt.owner = src.owner
                           AND idt.object_name = 'MY_PROCEDURE'
                  ORDER BY code_unit, line
                  /
                  
                  LINE CODE_UNIT          COLUMN_NAME TEXT  
                  4   STEVEN.MY_PROCEDURE N           l_n           my_data.n%TYPE;
                  10  STEVEN.MY_PROCEDURE N           FOR UPDATE OF n;
                  12  STEVEN.MY_PROCEDURE N           INSERT INTO my_data (n)
                  

                  希望有帮助!

                  在 livesql.oracle.com 上有更多 PL/Scope 示例.只需搜索pl/scope"(废话).

                  Lots more examples of PL/Scope at livesql.oracle.com. Just search for "pl/scope" (duh).

                  这篇关于查找 SQL 中引用的列名和表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 PL/SQL 创建 PDF 报告 下一篇:SQL查找人员条目的狗最多

                  相关文章

                    <bdo id='6X0zY'></bdo><ul id='6X0zY'></ul>

                  1. <i id='6X0zY'><tr id='6X0zY'><dt id='6X0zY'><q id='6X0zY'><span id='6X0zY'><b id='6X0zY'><form id='6X0zY'><ins id='6X0zY'></ins><ul id='6X0zY'></ul><sub id='6X0zY'></sub></form><legend id='6X0zY'></legend><bdo id='6X0zY'><pre id='6X0zY'><center id='6X0zY'></center></pre></bdo></b><th id='6X0zY'></th></span></q></dt></tr></i><div id='6X0zY'><tfoot id='6X0zY'></tfoot><dl id='6X0zY'><fieldset id='6X0zY'></fieldset></dl></div>
                  2. <tfoot id='6X0zY'></tfoot>

                    <small id='6X0zY'></small><noframes id='6X0zY'>

                      <legend id='6X0zY'><style id='6X0zY'><dir id='6X0zY'><q id='6X0zY'></q></dir></style></legend>