Parse SQL query and extract source tables and columns

Hello,
I have a set of SQL queries and I have to extract the source tables and columns from them.
For example:
Let's imagine that we have two tables
CREATE TABLE T1 (col1 number, col2 number, col3 number)
CREATE TABLE T2 (col1 number, col2 number, col3 number)
We have the following query:
SELECT
T1.col1,
T1.col2 + T1.col3 as field2
FROM T1 INNER JOIN T2 ON T1.col2=T2.col2
WHERE T2.col1 = 1
So, as a result I would like to have:
Order Table Column
1 T1 col1
2 T1 col2
2 T1 col3
Optionally, I would like to have a list of all dependency columns (columns used in "ON", "WHERE" and "GROUP BY" clauses:
Table Column
T1 col2
T2 col1
T2 col2
I have tried different approaches but without any success. Any help is appreciated. Thank you in advance.
Best regards,
Beroetz

I have a set of SQL queries and I have to extract the source tables and columns from them. In a recent db version you can use Re: sql injection question for this.

Similar Messages

  • Issue in data Extraction , Source tables having columns wth lengthe 60

    Hi BI Experts ,
    Here I have a issue while extracting the data from Oracle tables. I encountered some columns for which the length of character stream is more than 60 , some where around 200 to 300 , for example : Reason for some action , Comments , discription .
    I am not able to to treat them as master  data text since these fileds are coming with the Transaction data . In SAP BI we can have the data type CHAR with length max to 60 . Now how can I deal this situation in a better way ??
    Could you please come up with your ideas .
    Expecting interesting solutions
    Anurag

    Hello Charan,
    first check this Blog:
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417800)ID0294722750DB10878770002327649734End?blog=/pub/wlg/3705
    It may helps already.
    Anouter methode is to report from PSA Tables. But here no How-to is available.
    Br.
    Joerg

  • Classic Report CSV output failed to parse SQL query

    Hi,
    I'm trying to get a CSV output from a classic report. I'm generating the report based on a PL/SQL block that will return an SQL query. But when i download the CSV excel just gives me a:
    failed to parse SQL query:
    ORA-00936: Missing expression
    and shows me the query that the application is trying to parse. I'm also using bind variables (page items) in the PL/SQL block that is returning me the SQL query. I think that the reason that it fails to parse the query is that the query that is shown in excel has no bind variable values.
    Anyone got any ideas?

    Hi Arif,
    run your page in debug mode and check out the SQL statement which is actually executed for the report. That might help to diagnose what is going wrong.
    If you wish you can also post the report SQL statement which is getting executed.
    Regards
    Patrick
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • Chart Query and Failed to parse SQL query

    Hi,
    first of all, this is not a question. It is a reminder for me and maybe for someone with the same problem.
    I just fell over this for the 123124 time.
    I have a 3D Chart Query
    select sum(order_ok) value,
          count(*) maximum_value
    from      v_dialer_campaign
    where campaign_uuid = :P300_CAMPAIGN_IDSaving fails with
    "1 error has occurred Failed to parse SQL query!" ...
    Saving the query without validation works, but does not show any result in the chart.
    v_dialer_campaign is a view selecting from a view in a mssql db over database link and HS.
    running the select in sqlplus or toad works.
    Without any trace on freetds/unixodb/hs side, i would have not found the following line:
    [FreeTDS][SQL Server]The data types nvarchar and text are incompatible in the equal to operator.[FreeTDS][SQL Server]Statement(s) could not be prepared.
    Solution:
    with q as (select :P300_CAMPAIGN_ID val from dual)
    select     sum(order_ok) value,
         count(*) maximum_value
    from     v_dialer_campaign
    where     campaign_uuid in ( select val from q)Maybe the error output when validating the query should be included in the APEX error message.
    Same solution applies for dynamic LOV's reading from HS using a where clause.

    I tried your first query on Apex 3.2 and it created a nice dial chart.
    Is there any ORA-xxxxx error along with the "failed to parse SQL query" message? Did you double check column & table name spelling?
    P.S. The second query is invalid (a superfluous comma after the second column).

  • Sql query slowness due to rank and columns with null values:

        
    Sql query slowness due to rank and columns with null values:
    I have the following table in database with around 10 millions records:
    Declaration:
    create table PropertyOwners (
    [Key] int not null primary key,
    PropertyKey int not null,    
    BoughtDate DateTime,    
    OwnerKey int null,    
    GroupKey int null   
    go
    [Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
    With the following index:
    CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]    
    [PropertyKey] ASC,   
    [BoughtDate] DESC,   
    [OwnerKey] DESC,   
    [GroupKey] DESC   
    go
    Description of the case:
    For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
    following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
    declare @ownerKey int = 40000   
    select PropertyKey, BoughtDate, OwnerKey, GroupKey   
    from (    
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,       
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]   
    from PropertyOwners   
    ) as result   
    where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
    It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
    May be the slowness is due to as OwnerKey/GroupKey in the table  can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
    view.
    Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.

    create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
    insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
    from PropertyOwners
    go
    declare @ownerKey int = 1
    select PropertyKey, BoughtDate, OwnerKey, GroupKey
    from #result as result
    where result.[Rank]=1
    and result.[OwnerKey]=@ownerKey
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to identify the SQLs which are using the tables and new columns

    Hi
    I m using oracle 10G Database in windows. Developers have added some columns in some of the database tables and were asking to check whether there is some impact on performance or not. I have not done this performance tuning before. Kindly help me how to proceed further.
    How to obtain the sqls which are touching the tables and the new columns? It would be really great if you can help me with this.
    Thanks

    You can try to use DBA_DEPENDENCIES to get PL/SQL objects using tables: http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_1041.htm#i1576452.
    However if SQL code is not stored in database in a trigger, a procedure, a function, a package or a view, it is impossible to retrieve all SQL code referencing some table from database dictionary: for this you would have to analyze application source code.

  • References between source tables and mappings

    Hi,
    I'm looking for a table, view etc. in the repository which shows me references between source table and mappings?
    cheers,
    Bernhard

    Here's another one:
    http://www.nicholasgoodman.com/bt/blog/2005/04/01/owb-sources-and-targets-sql/
    select
    distinct 'TARGET',
    comp.map_name,
    comp.data_entity_name,
    comp.operator_type
    from
    all_iv_xform_map_components comp,
    all_iv_xform_map_parameters param
    where
    lower(operator_type)
    in ('table', 'view', 'dimension', 'cube')
    and param.map_component_id = comp.map_component_id
    and param.source_parameter_id is not null
    UNION
    select
    distinct 'SOURCE',
    t1.c1,
    t1.c2,
    t1.c3
    from
    (select
    comp.map_name c1,
    comp.data_entity_name c2,
    comp.operator_type c3,
    max(param.source_parameter_id) c4
    from
    all_iv_xform_map_components comp,
    all_iv_xform_map_parameters param
    where
    lower(operator_type) in
    ('table', 'view', 'dimension', 'cube')
    and param.map_component_id = comp.map_component_id
    group by
    comp.map_name, comp.data_entity_name, comp.operator_type) t1
    where t1.c4 is null
    order by 2,1

  • Can I put a SQL query into a bind variable and then use it to output report

    Hi,
    Can I put a SQL query into a bind variable and then use it to output report?
    I want to create a report and an item "text area" (say P1_TEXT) which can let user to input a SQL query(they are all technical users and knows SQL very well). Then, I use a bind variable (that text area) to store the SQL statement. Then, I add a submit button and I want to use the following to output the report:
    select * from (:P1_TEXT);
    Do you think it is possible to do that? Any known limitations for APEX in this area?
    Thanks a lot,
    Angela

    You can, but make sure it's what you really want to do. Make sure you are VERY familiar with SQL Injection. Most people who know what it is, go out of their way to prevent SQL Injection. You're going out of your way to allow it.
    You can try using &P1_TEXT. instead of bind variable syntax. Bind variables are one of the best ways to prevent SQL Injection, which is why it's not working for you.
    Once again, I strongly urge you to consider the implications of your app, but this suggestion should get it working.
    Tyler

  • Identify source tables and columns

    I would appreciate it if someone could point me toward an OWB table(s) or view(s) that will identify which source tables and columns are being used as input to an OWB map.
    Thanks,
    Tom Rehage

    Hi Tom,
    Have you checked Appendix D in the User Guide?
    Look at "Warehouse Builder Design Repository Public Views" under Warehouse Builder Public Views.
    Not sure whether you can find the distinction between source or target though.
    Good luck, Patrick

  • Failed to parse SQL query: ORA-01403: no data found

    I'm going to post and answer my own question in the hope that others will not have to struggle with this error.
    Using a report of the type PL/SQL Function Body Returning SQL and using generic columns you may run into this error
    failed to parse SQL query:
    ORA-01403: no data found
    The SQL will run stand alone but the report fails.
    There is a setting just below the source you should check:
    "Maximum number of generic report columns"
    In my case the number of columns was dynamic and when it exceeded the number set as the maximium number of generic columns I received the 1403 error.
    Hope this helps someone.
    Greg

    Thanks for much for the pointer. For anyone else struggling with this too, I found that my generic columns had unordered themselves. Reordering them solved the problem for me.
    Edited by: user11096971 on Jul 22, 2010 3:19 AM

  • Failed to parse SQL query by one user

    Hi all,
    in my app i have a text-item with a submit button. In this item i type a name and a report after the item-region show me the result(s). this works for all my users (>2000) perfectly, but one of this users become an error in the report-region:
    failed to parse SQL query:
    ORA-01403: no data found
    We try this with the same searchstring on the same computer/browser. If i logged in the result is ok, if the user logged in, the error message shows. If i try this on the computer from the user with me logged in, result ok. If the user try this on an other pc, results error.
    I have an productive and a developer workspace. In the developer workspace the user can try this perfectly without errors. Only in the productive workspace the error shows.
    The SQL-Select in the reprirt ist verry simple:
    select id
    , name
    , raum
    from table
    where instr(upper(name), upper(:P60_SEARCH))>0
    However all users can use this search-field with report perfectly, only this one user has the error. It is no restrictions on this item or report.
    Can anybody help me?

    Carsten,
    user preferences do not have anything to do with the fact where the user resides (apex built in, LDAP, whatever). User Preferences are saved for a named user and they are loaded next time the same user loggs in. For example, if you sort your report on a column x, apex will save this as a setting and next time you call the same report, this report will be sorted the same way. Since you don't have a permission to edit services, you should check your adminstrative permissions and conntact the real administrator of the workspace to do that "purge prefference" for you. I could bet this is the reason you are getting that strange error message.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------

  • Column sort gives "failed to parse SQL query"

    Hi folks,
    I have a page with a chart and 5 reports. All report columns are sortable.
    When I first navigate to the page from a menu, the chart and all reports display correctly. Given certain query criteria, reports 2 and 4 correctly return no data, and show my polite 'no data found' message.
    If I sort report 1 or 3 or 5 by clicking a column heading, the chart and reports 1, 3 and 5 display correctly, but in report regions 2 and 4 I then get
    failed to parse SQL query:
    ORA-06502: PL/SQL: numeric or value error: NULL index table key valueThese errors can be cleared by navigating to the page again from a menu.
    What's wrong? How can I fix it?
    I'm at 1.6.0.00.87, db 10.1.0.3.0.
    All ideas gratefully received.
    Thanks
    John D

    OK, I now have a workspace.
    I recreated the problem using page 1 of the Sample Application (app 15027).
    1 - Copy region "My Top Orders" to "My Top Orders 2" on page 1 (same display point, column 2).
    2 - Edit the SQL of "My Top Orders 2" to remove the ORDER BY clause.
    3 - Edit the columns of "My Top Orders 2" to make all columns other than ORDER_ID sortable.
    4 - Copy region "My Top Orders 2" to "My Top Orders 3" on page 1 (same display point, column 2)..
    5 - Run page 1
    6 - Click a column heading on "My Top Orders 2" and I got "failed to parse..." on "My Top Orders 3".
    BUT it's intermittent. Navigate away from page 1 then return, and you may find the error doesn't recur.
    So, what's up Doc?
    Many thanks,
    John

  • Give me the sql query which calculte the table size in oracle 10g ecc 6.0

    Hi expert,
    Please  give me the sql query which calculte the table size in oracle 10g ecc 6.0.
    Regards

    Orkun Gedik wrote:
    select segment_name, sum(bytes)/(1024*1024) from dba_segments where segment_name = '<TABLE_NAME>' group by segment_name;
    Hi,
    This delivers possibly wrong data in MCOD installations.
    Depending on Oracle Version and Patchlevel dba_segments does not always have the correct data,
    at any time esp. for indexes right after being rebuild parallel (Even in DB02 because it is using USER_SEGMENTS).
    Takes a day to get the data back in line (never found out, who did the correction at night, could be RSCOLL00 ?).
    Use above statement with "OWNER = " in WHERE for MCOD or connect as schema owner and use USER_SEGMENTS.
    Use with
    segment_name LIKE '<TABLE_NAME>%'
    if you like to see the related indexes as well.
    For partitioned objects, a join from dba_tables / dba_indexes to dba_tab_partitions/dba_ind_partitions to dba_segments
    might be needed, esp. for hash partitioned tables, depending on how they have been created ( partition names SYS_xxxx).
    Volker

  • Report failed to parse SQL query:ORA-01745: invalid host/bind variable name

    Hi,
    We are currently upgrading from v2.2.0.00.32 to v4.0.0.00.46.
    I have copied the applications onto our test server along with the various database objects and data etc.
    When I am running a report in v4, it is failing with the following error: "failed to parse SQL query: ORA-01745: invalid host/bind variable name".
    When I copy the SQL that builds the report into TOAD (on out test server) it runs OK so really cant see why it would fail in APEX. It works fine when I run the query in our APEX v2 and in TOAD in our live server.
    The query is as follows:
    SELECT
    aea.ALTERATION_ID
    ,aea.ALTERATION_ID "ALTERATION_ID_DISPLAY"
    ,aea.assembly_name "Revised BOM"
    ,assembly.description "Revised BOM Description"
    ,assembly.INVENTORY_ITEM_STATUS_CODE "Revised BOM Status"
    ,aea.BEFORE_CHANGE_QTY
    ,flv.MEANING "Alteration Type"
    ,aea.component_name "Part No"
    ,component.description "Part No Description"
    ,component.INVENTORY_ITEM_STATUS_CODE "Part No Status"
    ,aea.AFTER_CHANGE_QTY
    ,TO_CHAR(aea.last_update_date,'DD-MM-YYYY HH24:MI:SS')"Last Update Date"
    ,aea.LAST_UPDATE_BY
    ,aea.COMMENTS
    ,aea.ORACLE_CHANGE_NOTICE
    ,AEA.SELECTION_CRITERIA
    FROM XXMEL_APEX_ECO_ALTERATIONS aea
    , fnd_lookup_values flv
    , (SELECT INVENTORY_ITEM_STATUS_CODE
    ,segment1
    ,description
    FROM mtl_system_items_b
    WHERE 1=1
    AND organization_id = 26) component
    , (SELECT INVENTORY_ITEM_STATUS_CODE
    ,segment1
    ,description
    FROM mtl_system_items_b
    WHERE 1=1
    AND organization_id = 26) assembly
    WHERE 1=1
    AND aea.COMPONENT_NAME = component.segment1 (+)
    AND aea.assembly_NAME = assembly.segment1 (+)
    AND flv.lookup_code = aea.acd_type
    AND aea.eco = :P13_ECO
    AND flv.lookup_type = 'ECG_ACTION'
    AND modify_flag = 'Y'
    ANy help would be great,
    Thanks
    Chris
    Edited by: Cashy on 22-Nov-2010 04:13
    Edited by: Cashy on 22-Nov-2010 04:14

    For some reason, the updatable fields (this is a updateable report) where not connecting to the database properly. Whn I changed them to a report columns and removed the database field reference, the report rendered

  • Fail to parse SQL query after report attributes changes on sample app

    This errors occurs in the sample application istalled in Workspace PMW on the http://htmldb.oracle.com web site. Goto home page, edit Page 1, Select "Top Orders" in Region, select report attributes, change max count from 5 to 5 in "Layout and Pagination", apply changes, run page and parse SQL error occurs. Select "debug" and the following is shown regarding the query.
    0.10: query could not be parsed:
    SELECT a.ORDER_ID, a.ORDER_TIMESTAMP, a.CUSTOMER_ID,
    b.cust_last_name || ', ' || b.cust_first_name cust_name, NVL(a.ORDER_TOTAL, 0)
    FROM demo_orders a, DEMO_CUSTOMERS b
    WHERE a.customer_id = b.customer_id
    ORDER BY NVL(a.ORDER_TOTAL, 0) DESC order by 5 desc,5 desc
    failed to parse SQL query:
    ORA-00933: SQL command not properly ended
    I can't see that I'm doing anything wrong but maybe someone can shed some light on this!
    Thanks

    this is sort of an oversight on our part. what's going on is that the sample app installs with that order by clause in the query. at the same time, the report attributes page for that region has a default sort sequence value of "1 desc" (even though column heading sorting isn't enabled). when you go to that page and try to apply any change, htmldb tries to set things up correctly for you...and you end up with that double order by. the best way to avoid the issue is to remove the order by clause from the query on the Region Definition page.
    hope this helps,
    raj

Maybe you are looking for

  • Why do I get an error when clicking on topics in email?

    I subscribe to the forum posts that I create and by doing so I get an email when the thread has been updated. The email contains a link to the message thread but when I click I got an Apple.com webpage saying "An error has occurred". Does anyone else

  • Function Module to Return MM/DD/YYYY after 6 Months from today's Date

    Hi, I need to find out the Month/Date/Year, after 6 months from the given Date. Can any one please suggest me a suitable Function Module to get the MM/DD/YYYY after 6 months from current date. Appreciate your help! Thanks, Kannan.

  • My Ipod keeps on saying "itunes has detected an ipod in recovery mode...."

    My Ipod keeps on telling me that i need to "itunes has detected an ipod in recovery mode.You must restore this ipod before it can be used with itunes". I have restored it numerous times What should i do about this? Thanks for your help.

  • My iPhone 4S keeps turning on and off randomly

    I dropped my iPhone 4S in water two days ago, but I put it in rice almost immediately. It was working fine yesterday, but now it won't stop turning on and off randomly. Like it would stay on for maybe 1-5 minutes, but then the screen will turn weird

  • IPhoto quits unexpectedly constantly

    iPhoto 6.0.5 quits after a period of time, after attempting to select music from iTunes for a slideshow, etc. I have done a complete rebuild (using command+option at iPhoto startup) and a manual rebuild but nothing has changed. I recently (August 200