Parse SQL: How to extract column names, table names from a SQL query

Hi all,
I have a requirement wherein a SQL query will be given in a text file.
The text file has to be read (probably using text_io package), the SQL query needs to be parsed and the column names, table names and where clauses have to be extracted and inserted into separate tables.
Is there a way to do it using PL/SQL ?
Is there a PL/SQL script available to parse and extract column names, table names etc ?
Pls help.
Regards,
Sam

I think I jumped to conclusion too early saying it is completely possible and straight forward. But after reading through your post for one more time I realised you are not interested only in the column_names, also the table_names and the predicates .
>
SQL query needs to be parsed and the column names
>
The above is possible and straight forward using the dbms_sql package.
I am pasting the same information as I did in the other forum.
Check this link and search for Example 8 and .
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#sthref6136
Also check the working example from asktom
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
>
table names and where clauses have to be extracted
>
Now this is the tricky bit. You can extract the list of tables by getting the sql_id from v$sql and joining it with v$sql_plan. But sometimes you may not get all the results because the optimizer may choose to refine your query (check this link)
http://optimizermagic.blogspot.com/2008/06/why-are-some-of-tables-in-my-query.html
and you can get the predicate information from the same table v$sql_plan but I will leave that area for you to do some R&D.
Regards
Raj
Edited by: R.Subramanian on Dec 10, 2008 3:14 AM

Similar Messages

  • How to know  columns and table name  whose column size are modified

    Hi guys
    I want to know which all columns in the tables are modify
    i.e. list of columns and table name whose column size are modified
    Step1 :
    CREATE TABLE employees
    ( employee_number number(5) ,
    employee_name varchar2(50) ,
    department_id number(10)
    CREATE TABLE Supplier
    ( Supplier_number number(5) ,
    Supplier_name varchar2(50) ,
    CREATE TABLE customers
    ( customer_id number(10) not null,
    customer_name varchar2(50),
    address varchar2(50),
    city varchar2(50),
    state varchar2(25),
    zip_code varchar2(10),
    Step2 :
    Alter table employees
    MODIFY employee_number number(10)
    ALTER TABLE supplier
    MODIFY supplier_name varchar2(100)
    step3
    query to dispaly
    columnname table name
    employee_number employees
    supplier_name supplier
    How to know columns and table name whose column size are modified
    could you please provide query
    Thanks in Advance

    09:35:50 SQL> desc dba_objects
    Name                            Null?    Type
    OWNER                                  VARCHAR2(30)
    OBJECT_NAME                             VARCHAR2(128)
    SUBOBJECT_NAME                         VARCHAR2(30)
    OBJECT_ID                             NUMBER
    DATA_OBJECT_ID                         NUMBER
    OBJECT_TYPE                             VARCHAR2(19)
    CREATED                             DATE
    LAST_DDL_TIME                             DATE
    TIMESTAMP                             VARCHAR2(19)
    STATUS                              VARCHAR2(7)
    TEMPORARY                             VARCHAR2(1)
    GENERATED                             VARCHAR2(1)
    SECONDARY                             VARCHAR2(1)
    NAMESPACE                             NUMBER
    EDITION_NAME                             VARCHAR2(30)LAST_DDL_TIME can be utilized

  • How to look for the Table Name

    Hi Friends,
    Sometimes we need to download the table for the desired information if the same is not available from a particular report. How to look for the table name? Is there a report or a particular feild, where we can find the name of the particular table?
    Thanks for the assistance.
    Regards

    Hi Friend,
    If you want to see the structures then go to SE11. Sometimes it happens that you cannot find the table names but only fields. In such case, if you want to find the Table names which is not available, then go to SE90.
    Abap Dictionary > Fields > Table Fields.
    Now Enter the Field name in Right Hand Side of the screen then Execute. You will see the all tables by which that Fields are used.
    Regards,
    Jigar

  • How to find out the table name

    hi,
    how to find out the table name in which the data from a particular structure in a particular screen is saved,
    please tell me the procedure to find out the table name for saving the structure data that is inputted at runtime.
    Thanks,
    chinnu

    Hi Chinnu,
    Below are the tables that are referred to find out the table names
    DD02L Table contains the SAP Tables.
    DD02T Table contains the SAP Table Texts.
    DD01L Table contains the Domains
    DD01T Table contains the Domain Texts.
    DD03L Table contains the Table Fields.
    DD03T Table contains the Table Field Texts. (Language Dependent)
    DD04L Table contains the Data Elements.
    DD04T Table contains the Data Element Texts.
    DD05s Table contains the Foreign Key Fields
    last words with L and T only. L->Database Fetch T-> Text
    And the procedure to retrive the table name is as follows
    1. Go to se11
    2. Enter table name DD03T and execute
    3. In the next screen you can find Tables, fields, test etc. there you can enter the field name in the fields 
      and execute.
    4. you can get all tables which contains the field.
    I hope this will solve your problem
    Regards,
    Chandru

  • How to identify the psa table names in bi 7?

    Hi all,
    How to identify the psa table names in bi 7?  i need to know the psa table name in bi 7?
    as well as i need to check whether any historical data loads is there for psa for a particular period?
    How to filter for a particular data in the psa in bi 7?
    Thanks
    Pooja

    Hi Pooja,
    A)How to identify the psa table names in bi 7? i need to know the psa table name in bi 7?
    Double click on the PSA and CTRLSHIFTF5 --->in PSA properties -->PSA table ..u can find the name here ....
    B)as well as i need to check whether any historical data loads is there for psa for a particular period?
    usually as SAP best practise we will not keep data in PSA for not more than 30 days or at the amx 60 days..you may not find historical data here..however to find the oldest data -->Right Click >Manage>Give some old date ,say 01.01.2005 in the Request newer than ...and Refresh.....
    Other way is to find out in the Data provider i.e in the Cube or DSO ...
    How to filter for a particular data in the psa in bi 7?
    a)Do not map it
    b)in the DTP...Filter it ....i.e from PSA -->CUBE/DSO....
    c)Or write a routine also in start routine ...
    Rgds
    SVU123

  • How to Extract Customized Financial Statement Version from R/3 to BW

    Hi Gurus,
    Could anybody tell me how to Extract Customized Financial Statement Version from R/3 to BW. Also send me docs on FICO and COPA extraction from R/3 to BW.
    Thanks in advance...
    Regards
    Rafi

    Sayed
    Please see this BW Best Practice link
    http://help.sap.com/bp_biv133/
    http://help.sap.com/bp_biv235/BI_EN/html/BW/COPABaselineAnal.htm
    http://help.sap.com/bp_biv235/BI_EN/html/BW/ControllingAnalysis.htm
    COPA Business content
    http://help.sap.com/saphelp_nw04/helpdata/en/28/3dc7393b26da1de10000000a114084/content.htm
    Hope this helps
    Thnaks
    Sat

  • Require  field name , Table name

    Hi All,
    For a Z development i need a field name & table name
    the requirement is for which FG material this SFG is produced.,suppose A is the FG material
    X,Y,Z are the semifinished materials required to produce A ., when going for production for X or Y o Z it should tell for which Fg this is produced
    Please give your input
    Regards
    Anand Srinivasan

    Hi
    Have checked RESB & AUFM tables before but couldnt get the FG link, it is pegged to the next level only
    If you keep on passing the pegged requirements then only the FG link is coming
    at the time of prodn order creation of SFG they want to generate this report
    The backdrop  in this is the same  SFG can be used in many FG
    Regards
    Anand Srinivasan

  • How to extract the actual XML document from soap message?

    My problem is " how to extract the actual XML document from soap message? "
    i just want to extract the attachment i.e. (pure XML document without any soap header or envolope).
    i could be ver thank full if u could solve my problem.
    [email protected]

    Hi,
    This is some skeleton code for extracting an attachment from a SOAPMessage.
    import javax.activation.DataHandler.;
    import javax.xml.soap.*;
    import javax.xml.message.*;
    Iterator allAttachments = message.getAttachments();
    AttachmentPart ap1 = null;
    while(allAttachments.hasNext()){
    ap1 = (AttachmentPart)allAttachments.next();
    //Check that the attachment is correct one. By looking at its mime headers
    //Convert the attachment part into its DOM representation:
    if(ap1.getContentType() == "text/xml"){
    //Use the activation dataHandler class to extract the content, then create a StreamSource from
    //the content.
    DataHandler attachmentContent = ap1.getDataHandler();
    StreamSource attachmentStream = new StreamSource(attachmentContent.getInputStream());
    DOMResult domAttachment = getDOMResult(attachmentStream);
    domAttachment holds an xml representation of the attachment.
    Hope this helps.

  • SSRS Reports level how to find out All tables names & columns list to display dynamically SQL Query????

    Hi Team,
    I Have one requirement,In SSRS Reporsitory 3000 reports are available.
    My end user requirement All 3000 reports are used Table names & columns list of each wise to display single table or single result set.
    I find out all 3000 reports details are diplayed single results set like
    Report Id,Path,Dataset,Source Query Text,Datasource
    In Source Query Text  column level All reports Queries are available but I want Each Report wise Table name & columns List.If any solution Please share me.
    Regards
    Rama

    Hi Ramakoteswara,
    According your description, you want to show used tables and columns of each report, and display is into a single result set. Right?
    In this scenario, we don't know where to find a column contains the Source Query Text. With my understanding, in Reporting Services, we have Catalog table in ReportServer DataBase, it has a column called Content stores the report code (.xml). In the
    code we can find the Query and Fields. Then you need to use VB/C# code to parse each .xml code of each report and fetch out the table name and columns. We do not support writing any queries against SSRS DataBase or parsing data records in any
    table.
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How can I get the table name of my column?

    I'm using the JDK 1.3 trying to get a table name of a column from a result set. Regardless of what driver I'm using (ODBC Bridge/Oracle) I always get a null returned. Does this method work?
    If not, if I'm doing an SQL query that uses more than 1 table and each table has a return of the same column name, how do I distinguish which table the column is from. Thanks

    You can use ResultSetMetaData interface and method
    String getTableName(int column)
    This should return you the table name.
    To get ResultSetMetaData object, you can use
    ResultSetMetaData getMetaData()
    method of ResultSet interface.
    HTH

  • JKM DB2 400 column and table name 10 character limit

    I am trying to set up CDC on an iSeries. I have successfully loaded data with the LKM SQL to Oracle, and now I want to set up CDC for the table and am trying to use "JKM DB2 400" . I get invalid token errors when I try to start journalizing, and it appears to be the table and column names, used to set up CDC, which are more than the 10 character limit. Tables like SNP_JRN_SUBSCRIBER seem to come from the getJrnInfo function and other table and column names are hard coded. I want to copy the JKM and reduce all of the names to less than 10 characters.
    Where else are these names used? How does the interface know which table names to use when set to use only journalized data and how can I change it to use the new shorter names? Is there a better solution?

    Thanks to all for assistance. It turns out that the 10 character limit, about which the server people warned me, isn't an issue with my ODBC connection. The invalid token error was being caused by some missing qualifiers in the generated sql which caused appearances of ".tablename" rather than "tablename" and other similar. I was able to modify the knowledge module to eliminate this issue and the CDC worked correctly on my first test.

  • Table column and table name

    Hi Experts,
    I just want to ask is there any procedure to know the table name and the corrosponding column name when you have only data with you.
    Suppose you have a string say "India". Now i want to know the name of the column and corrosponding tablename
    which holds the value "India".
    Thanks
    Rajat

    Solutions previously provided by michaels...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • How to determine column length semantics through ANSI Dynamic SQL ?

    I am looking for a way to determine the length semantics used for a column through ANSI Dynamic SQL.
    I have a database with NLS_CHARACTERSET=AL32UTF8.
    In this database I have the following table:
    T1(C1 varchar2(10 char), C2 varchar2(40 byte))
    When I describe this table in SQL*Plus, I get:
    C1 VARCHAR2(10 CHAR)
    C2 VARCHAR2(40)
    In my Pro*C program (mode=ansi), I get the select statement on input, use PREPARE method to prepare it and then use the GET DESCRIPTOR method to obtain colum information for output:
    GET DESCRIPTOR 'output_descriptor' VALUE :col_num
    :name = NAME, :type = TYPE,
    :length = LENGTH, :octet_length = OCTET_LENGTH
    For both C1 and C2 I get the following:
    :type=12
    :length=40
    :octet_length=40
    So, even if I know that my database is AL32UTF8, there doesn't seem to be a way for me to determine whether char or byte length semantics were used in C1 and C2 column definitions.
    Does anybody know how I can obtain this information through ANSI Dynamic SQL?
    Note: the use of system views such as ALL_TAB_COLUMNS is not an option, since we wish to obtain this information even for columns in a complex select statements which may involve multiple tables.
    Note: I believe OCI provides the information that we need through OCI_ATTR_DATA_SIZE (which is in bytes) and OCI_ATTR_CHAR_SIZE (which is in chars). However, switching to OCI is something we would like to avoid at this point.

    Yes, I was wondering which forum would be the best for my question. I see similar questions in various forums, Call Interface, SQL and PL/SQL and Database - General. Unfortunately there is no Pro*C or Dynamic SQL forum which would be my first choice for posting this question.
    Anyway I now posted the same question (same subject) in the Call Interface forum, so hopefully I'll get some answers there.
    Thank you for the suggestion.

  • How to find out all table names which has a particular data

    Hi,
    How could i get all the table names from a database(for a schema) which has data 'KST6490' in one of the fileds in the table.There are many tables with this
    data. Data type is Varchar2. Thanks.

    One approach would be to create a procedure which retrieves the name of all tables in the schema using the user_tables view. Then use the user_tab_columns view to get all the column names and types. If the type is varchar2, then dynamically create a sql statement which runs a query on that column using the value which you are looking for. You would need two cursor loops for this approach: one for tables and one for columns. This approach requires good PL/SQL programming skills.
    Alternately, many query tools, such as Golden, provide a search capability on query results. Just do a select * from the table and search on the results. This would need to be done table by table and the results would have to fit in the memory available to the tool.
    Alternately, you can write table contents to a text file on the a server and then search the text file using operating system tools such as grep. This would require good OS scripting skills.

  • How to use full qualified table names in RPD

    Hi,
    We are implementing the BI Financial Analytics, we have a requirement to use diffrent user accounts for DAC , ETL and OBIEE
    DAC, ETL we are using user as XXOBI
    For OBIEE RPD we have to use user with read only access such as XXOBI_APP
    How can i make the changed to BI server / RPD to use full qualified names.
    I have tried to select the Full Qualified table name property in Oracle Datawarehouse connection pool setting.
    If i enable that all my sql query is showing tables as catalog.dbo.w_party_d ( my tables in physical layer showing under catalaog -> dbo -> all tables and joins)
    Any help in this is appreciated.
    Thanks
    Kris

    kmangamuri wrote:
    Hi,
    We are implementing the BI Financial Analytics, we have a requirement to use diffrent user accounts for DAC , ETL and OBIEE
    DAC, ETL we are using user as XXOBI
    For OBIEE RPD we have to use user with read only access such as XXOBI_APP
    How can i make the changed to BI server / RPD to use full qualified names.
    I have tried to select the Full Qualified table name property in Oracle Datawarehouse connection pool setting.
    If i enable that all my sql query is showing tables as catalog.dbo.w_party_d ( my tables in physical layer showing under catalaog -> dbo -> all tables and joins)
    Any help in this is appreciated.
    Thanks
    KrisAre you saying you just need to access the database using different accounts? If that is the case, why dont you just update the connection pool settings like username and password with XXOBI_APP account which you are supposed to be using for OBIEE?

Maybe you are looking for

  • How to sum the quantity in opportunity ?

    Hi all, On the opportunity detail page, you can add an "opportunity product revenue". For each record you define the quantity and the purchase price. When you click on the "Update opportunity Totals", the revenue field from opportunity is automatical

  • Regarding topdown list box

    how to place topdown list box in selection screen

  • Dreaded freeze with grey "restart" box

    Hi all, It's been a while since I last had an issue. Hopefully I can resolve this with your help. I've got this iBook G4 (1.33 GHz PPC; 1 GB RAM; HD not full) that's been solid and steady for a couple years, and recently these last 2 days, I've gotte

  • How to construct alias view (source) in Mapping Level

    Hi All, I have the following logic, in PL/SQL Code as follows: from source a, source b where a.PLKC = b.PLKC and a.PLDO = b.PLDO and a.PLDC = b.PLDC and a.PLLN = b.PLLN and b.PLAD > 0 ) How can we implement same logic in Mapping level by using Joiner

  • Programing

    Hello friends... I want to know that how can I make the connection with two tables in the database of oracle with java. I know that it can be done with JDBC but I can not select two tables simultaneously in a single connection. \ Please help me in de