Subqueries in From clause queries

I'm having a problem using a FROM CLAUSE query Query Data Source Type on an
Oracle Applications template form.
I've successfully created a form with a single data block having a single item
INVENTORY_ITEM_ID, with the Query Data Source Name as:
(SELECT INVENTORY_ITEM_ID FROM mtl_org_assign_v x WHERE 1=1 AND
master_organization_id = 86 AND NVL(eam_enabled_flag, 'N') = NVL('N', 'N') AND
inventory_item_id = 2)
however, if I add a subquery to the statement:
(SELECT INVENTORY_ITEM_ID FROM mtl_org_assign_v x WHERE 1=1 AND
master_organization_id = 86 AND NVL(eam_enabled_flag, 'N') = NVL('N', 'N') AND
inventory_item_id = 2 AND EXISTS ( SELECT 'x' FROM org_organization_definitions
ood WHERE ood.organization_id = x.organization_id AND ood.inventory_enabled_flag
= 'Y' ))
the whole thing blows up!! (i.e. throws a java exception and closes the
application) I've tried and run the query directly from SQL*Plus no problem.
I've also built a view with it and queried that directly - no problem.
The reason I am using this query is that I am trying to build up to a much more
complex query with a UNION and bind variables which doesn't work - I'm trying to
isolate the root cause, so I'm doing it one step at a time.
The query I'm finally trying to have in there is:
SELECT DECODE (organization_id, :master_org_id, 1, 2),
assigned_flag,organization_id, inventory_item_id, organization_code,
organization_name, primary_unit_of_measure_tl,
cost_of_sales_account, sales_account, expense_account,
encumbrance_account
FROM mtl_org_assign_v x
WHERE 1=1
AND master_organization_id = :master_org_id
AND NVL (eam_enabled_flag, 'N') = NVL (:EAM_ITEM_FLAG, 'N')
AND inventory_item_id = :inventory_item_id
AND EXISTS (
SELECT 'x'
FROM org_organization_definitions ood
WHERE ood.organization_id = x.organization_id
AND ood.inventory_enabled_flag = 'Y'
UNION
SELECT DECODE (organization_id, :master_org_id, 1, 2),
assigned_flag,organization_id, inventory_item_id, organization_code,
organization_name, primary_unit_of_measure_tl,
cost_of_sales_account, sales_account, expense_account,
encumbrance_account
FROM mtl_org_assign_v x
WHERE 1=1
AND master_organization_id = :master_org_id
AND NVL (eam_enabled_flag, 'N') = NVL (:EAM_ITEM_FLAG, 'N')
AND EXISTS (
SELECT 'x'
FROM org_organization_definitions ood
WHERE ood.organization_id = x.organization_id
AND ood.inventory_enabled_flag = 'Y'
AND (inventory_item_id IS NULL
AND organization_id IN (
SELECT
organization_id
FROM mtl_org_assign_v
WHERE inventory_item_id IS NULL
MINUS
SELECT organization_id
FROM mtl_org_assign_v
WHERE inventory_item_id = :inventory_item_id
ORDER BY
1 ASC
,2 DESC
,3
Any suggestions?

The reason bind variable don't work is that they are not possible in a FROM clause query. We simply pass the string to the database and it does not know anything about the value of a bind variable. If you want to pass a bind variable you will have to create the string with the values concatenated into it:
sqlstring:='SELECT DECODE (organization_id, '||:org.master_org_id'||', 1, 2)';
See note 104771.1 for an example.
That Forms crashes when you add a sub query could be a bug I am not sure. Could you use a view instead, possibly?

Similar Messages

  • From clause query works ok in form designer,  gets an ORA-01422 ran on web

    I am using forms 6i patch 9 with 10g database.
    I have two ‘FROM clause queries’ fired via a block/key-exeqry trigger in a if/elsif.
    The first/top SET BLOCK PROPERTY works perfect and populates the block.
    But the bottom/second SET BLOCK PROPERTY select (after the elsif)
    Is also based on a user entered field value and generates a ora-01422 error.
    The problem is that both top and bottom set block properties
    work fine when ran in forms designer,
    But when I compile it on the app_server and run the web version
    1. the top all ‘FROM clause query’ works fine
    2. the bottom ‘FROM clause query’ works fine if only one record to return.
    3. the bottom ‘FROM clause query’: gets the ora-01422 if > 1 record to return.
    FRM-40735: KEY–EXEQRY trigger raised unhandled exception ORA-01422
    The ORA-01422: ‘Exact fetch returned more than the exact number of rows’.
    Both set block property selects ‘share’ a block property/where clause of FAC_ID = :FACILITIES.ID
    The entered value in the entry field should populate 1 to many associated records
    in the bottom (elsif) set block property (and does so correctly when ran in forms designer)
    The block’s key-exeqry code:
    –-query all records associated with fac_id only
    if (:emission_stacks.stack_id_num is null) then
         SET_BLOCK_PROPERTY('EMISSION_STACKS',QUERY_DATA_SOURCE_NAME,
         '(SELECT C.ID, A.ID EP_ID,A.FAC_ID,A.NUM,A.DESCRIPTION,C.PARENT_MODE_ID,
    C.STACK_ID, C.CAPTURE_PERCENT, C.CAPTURE_METHOD, C.DATE_TESTED
    FROM EMISSION_POINTS A,
    EP_MODES B,
    CAPTURING_DEVICES C
    WHERE A.ID = B.EP_ID AND
    B.ID = C.PARENT_MODE_ID AND
    C.CD_ID IS NULL AND
    C.PARENT_MODE_ID IS NOT NULL AND
    C.STACK_ID IS NOT NULL)');
    EXECUTE_QUERY;
    elsif
    (:emission_stacks.stack_id_num is not null) then
    –-(query all records associated with fac_id and the entry field value)
    SET_BLOCK_PROPERTY('EMISSION_STACKS',QUERY_DATA_SOURCE_NAME,
         '(SELECT C.ID, A.ID EP_ID, A.FAC_ID, A.NUM, A.DESCRIPTION, C.PARENT_MODE_ID,
    C.STACK_ID, C.CAPTURE_PERCENT, C.CAPTURE_METHOD, C.DATE_TESTED
    FROM EMISSION_POINTS A,
    EP_MODES B,
    CAPTURING_DEVICES C,
    STACKS S
    WHERE A.ID = B.EP_ID AND
    B.ID = C.PARENT_MODE_ID AND
    C.STACK_ID = S.ID AND
    C.CD_ID IS NULL AND
    C.PARENT_MODE_ID IS NOT NULL AND
    C.STACK_ID IS NOT NULL AND
    S.NUM = '''||:emission_stacks.stack_id_num||''')');
    EXECUTE_QUERY;
    ** I have multiple database items in the block.
    Data block properties:
    Database/
    Data Base Block = Yes
    Query Allowed= Yes
    Is there a way to overcome the ora-01422?
    And populate the block with multiple rows(records)?
    Any suggestions appreciated.

    Sorry, false alarm, I made a mistake
    the form is working fine the way it should,
    without error. (No ora-01422 errror is occurring now.)
    I just got a new version of humming bird,
    which I used to compile the form with
    and did not have the binary switch on:
    --long story short, a new fmx was not created
    and I was not seeing the current version of screen
    at runtime.
    Thank you.

  • Connect By not working with nested queries in from clause.

    Using Connect By on a query which has a nested from clause(The from clause fetches around 100k records) gives incorrect results but if the same nested queries are used to build a table and the Connect By is used on the table then the output is correct.
    I put the nested queries in a 'WITH' clause and got the correct output also.
    I am not sure how to give the code here as you would need dump to make them work.
    I am giving the a sample code:
    --Non Working Code
    SELECT     con_item, prod_item, compsite, bcsite, ibrsite, res
          FROM (SELECT con_item, prod_item, compsite, bcsite, ibrsite, res
                  FROM (SELECT bd.item AS con_item, bd.fromid AS compsite,
                               bd.toid AS bcsite, bd.toid AS ibrsite,
                               bd.bodname AS ID, bd.item AS prod_item,
                               'BOD' AS res
                          FROM TABLE1 bd
                        UNION
                        SELECT bc.item AS con_item,
                               bc.componentsiteid AS compsite,
                               bc.siteid AS bcsite, ibr.siteid AS ibrsite,
                               ibr.routingid AS ID, ibr.item AS prod_item,
                               op.resourcename AS res
                          FROM TABLE2 ibr,
                               TABLE3 bc,
                               TABLE4 op
                         WHERE ibr.bomid = bc.bomid
                           AND ibr.siteid = bc.siteid
                           AND ibr.routingid = op.routingid(+))
                 WHERE con_item IN ('SCFCD0T9B', 'SWXCD0S9B')
                   AND ibrsite LIKE 'CRCW%HSM')
    START WITH ibrsite = 'CRCW_QA_HSM' AND prod_item = 'SWXCD0S9B'
    CONNECT BY PRIOR con_item = prod_item AND PRIOR compsite = bcsiteWorking Code:
    --The table TEST_V is constructed on the from clause of above query
    SELECT     CON_ITEM, PROD_ITEM, COMPSITE, BCSITE, IBRSITE, RES
          FROM TEST_V
    START WITH IBRSITE = 'CRCW_QA_HSM' AND PROD_ITEM = 'SWXCD0S9B'
    CONNECT BY PRIOR CON_ITEM = PROD_ITEM AND PRIOR COMPSITE = BCSITEAlso another working code:
    WITH SUB AS
         (SELECT BD.ITEM AS CON_ITEM, BD.FROMID AS COMPSITE, BD.TOID AS BCSITE,
                 BD.TOID AS IBRSITE, BD.BODNAME AS ID, BD.ITEM AS PROD_ITEM,
                 'BOD' AS RES
            FROM TABLE1 BD
          UNION
          SELECT BC.ITEM AS CON_ITEM, BC.COMPONENTSITEID AS COMPSITE,
                 BC.SITEID AS BCSITE, IBR.SITEID AS IBRSITE, IBR.ROUTINGID AS ID,
                 IBR.ITEM AS PROD_ITEM, OP.RESOURCENAME AS RES
            FROM TABLE2 IBR, TABLE3 BC, TABLE4 OP
           WHERE IBR.BOMID = BC.BOMID
             AND IBR.SITEID = BC.SITEID
             AND IBR.ROUTINGID = OP.ROUTINGID(+))
    SELECT     CON_ITEM, PROD_ITEM, COMPSITE, BCSITE, IBRSITE, RES, LEVEL
          FROM SUB
    START WITH PROD_ITEM = 'SWXCD0S9B' AND IBRSITE = 'CRCW_QA_HSM'
    CONNECT BY PRIOR COMPSITE = BCSITE AND PRIOR CON_ITEM = PROD_ITEMI am sorry if I am giving incorrect syntax, please let me know if my giving the dump of table be of any help.
    Regards,
    Vikram
    Edited by: BluShadow on 11-Jan-2012 11:05
    fixed {noformat}{noformat} tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi, Vikram,
    Welcome to the forum!
    user2765706 wrote:
    Using Connect By on a query which has a nested from clause(The from clause fetches around 100k records) gives incorrect results but if the same nested queries are used to build a table and the Connect By is used on the table then the output is correct.
    I put the nested queries in a 'WITH' clause and got the correct output also.What exactly is the problem? Why not use one of the queries that gives the correct output? I find that WITH clauses are a lot easier to understand and debug than in-ine views, anyway.
    Are you just wondering why one of the queries doesn't work?
    I am not sure how to give the code here as you would need dump to make them work. You're absolutely right! You need to post some sample data and the results you want from that data. Without that, it's much harder for people to understand what the problem is, or how to fix it.
    I am giving the a sample code:
    --Non Working CodeLet's call this Query 1.
    SELECT     con_item, prod_item, compsite, bcsite, ibrsite, res
    FROM (SELECT con_item, prod_item, compsite, bcsite, ibrsite, res
    FROM (SELECT bd.item AS con_item, bd.fromid AS compsite,
    bd.toid AS bcsite, bd.toid AS ibrsite,
    bd.bodname AS ID, bd.item AS prod_item,
    'BOD' AS res
    FROM TABLE1 bd
    UNION
    SELECT bc.item AS con_item,
    bc.componentsiteid AS compsite,
    bc.siteid AS bcsite, ibr.siteid AS ibrsite,
    ibr.routingid AS ID, ibr.item AS prod_item,
    op.resourcename AS res
    FROM TABLE2 ibr,
    TABLE3 bc,
    TABLE4 op
    WHERE ibr.bomid = bc.bomid
    AND ibr.siteid = bc.siteid
    AND ibr.routingid = op.routingid(+))
    WHERE con_item IN ('SCFCD0T9B', 'SWXCD0S9B')
    AND ibrsite LIKE 'CRCW%HSM')
    START WITH ibrsite = 'CRCW_QA_HSM' AND prod_item = 'SWXCD0S9B'
    CONNECT BY PRIOR con_item = prod_item AND PRIOR compsite = bcsite
    [\CODE]
    Working Code:Let's call this Query 2.
    --The table TEST_V is constructed on the from clause of above query
    SELECT     CON_ITEM, PROD_ITEM, COMPSITE, BCSITE, IBRSITE, RES
    FROM TEST_V
    START WITH IBRSITE = 'CRCW_QA_HSM' AND PROD_ITEM = 'SWXCD0S9B'
    CONNECT BY PRIOR CON_ITEM = PROD_ITEM AND PRIOR COMPSITE = BCSITE
    [\CODE]Why does Query 1 not do the same thing as Query 2? That depends on what is in test_v. Only you know what test_v is, so only you can say. If you'd post the code that created test_v, maybe somebody else could help.
    Also another working code:Let's call this Query 3.
    WITH SUB AS
    (SELECT BD.ITEM AS CON_ITEM, BD.FROMID AS COMPSITE, BD.TOID AS BCSITE,
    BD.TOID AS IBRSITE, BD.BODNAME AS ID, BD.ITEM AS PROD_ITEM,
    'BOD' AS RES
    FROM TABLE1 BD
    UNION
    SELECT BC.ITEM AS CON_ITEM, BC.COMPONENTSITEID AS COMPSITE,
    BC.SITEID AS BCSITE, IBR.SITEID AS IBRSITE, IBR.ROUTINGID AS ID,
    IBR.ITEM AS PROD_ITEM, OP.RESOURCENAME AS RES
    FROM TABLE2 IBR, TABLE3 BC, TABLE4 OP
    WHERE IBR.BOMID = BC.BOMID
    AND IBR.SITEID = BC.SITEID
    AND IBR.ROUTINGID = OP.ROUTINGID(+))
    SELECT     CON_ITEM, PROD_ITEM, COMPSITE, BCSITE, IBRSITE, RES, LEVEL
    FROM SUB
    START WITH PROD_ITEM = 'SWXCD0S9B' AND IBRSITE = 'CRCW_QA_HSM'
    CONNECT BY PRIOR COMPSITE = BCSITE AND PRIOR CON_ITEM = PROD_ITEM
    [\CODE]Why does Query 1 not do the same thing as Query 3? Query 1 has these conditions:
    ...           WHERE con_item IN ('SCFCD0T9B', 'SWXCD0S9B')
                    AND ibrsite LIKE 'CRCW%HSM'but Query 3 does not.
    I am sorry if I am giving incorrect syntax, please let me know if my giving the dump of table be of any help.Yes, that always helps. Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data. Simplify the problem as much as possible. For example, if you have the same problem when you leave out one of the tables, then don't include that table in the problem.
    Always say what version of Oracle you're using. This is especially important with CONNECT BY queries, because every version since Oracle 7 has had major improvements in this area.

  • Is it possible to create a view where table in the From clause changes name

    is it possible to create a view from a from a table like this
    create view my_view as select id, col1, col2, result from <<my_latest_cacahe_table>>;
    the table in the from clause changes the name .
    I have another table which indicates the the latest name of my cache tables. Always there are two records there. The latest one and previous one.
    select * from cache_table_def
    table_name cache_table_name refresh_date
    my_table cache_table245 1/23/2012
    my_table cache_table235 1/22/2012
    create table cache_table_def (table_name varchar2(25), cache_table_name varchar2(25), refresh_date date);
    insert into cache_table_def values( 'my_table','cache_table245','23-jan-2012');
    insert into cache_table_def values ( 'my_table','cache_table546','22-jan-2012');
    create table cache_table245 (id number, col1 varchar2(50), col2 varchar2(20), result number);
    insert into cache_table245 values(1, 'test123', 'test345',12.12);
    insert into cache_table245 values (2, 'test223', 'test245',112.12);
    create table cache_table235 (id number, col1 varchar2(50), col2 varchar2(20), result number);
    insert into cache_table235 values (1, 'test123', 'test345',92.12);
    insert into cache_table235 values (2, 'test223', 'test245',222.12);
    what I need to do is find the latest cache_table name for my_table and use that in my view defintion
    When user select from the the view it always reurns the data from the latest cache_table
    is it possible to do something like this in oracle 11g?
    I have no control on the cache tables names. that is why I need to use the latest name from the table.
    Any ideas really appreciated.

    I've worked up an example that does what you ask. It uses the SCOTT schema EMP table. Make two copies of the EMP table, EMP1 and EMP2. I deleted dept 20 from emp1 and deleted dept 30 from emp2 so I could see that the result set really came from a different table.
    -- create a context to hold an environment variable - this will be the table name we want the view to query from
    create or replace context VIEW_CTX using SET_VIEW_FLAG;
    -- create the procedure specified for the context
    - we will pass in the name of the table to query from
    create or replace procedure SET_VIEW_FLAG ( p_table_name in varchar2 default 'EMP')
      as
      begin
          dbms_session.set_context( 'VIEW_CTX', 'TABLE_NAME', upper(p_table_name));
      end;
    -- these are the three queries - one for each table - none of them will return data until you set the context variable.
    select * from emp where 'EMP' = sys_context( 'VIEW_CTX', 'TABLE_NAME' );
    select * from emp1 where 'EMP1' = sys_context( 'VIEW_CTX', 'TABLE_NAME' );
    select * from emp2 where 'EMP2' =  sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    -- this is how you set the context variable depending on the table you want the view to query
    exec set_view_flag( p_table_name => 'EMP' );
    exec set_view_flag( p_table_name => 'EMP1' );
    exec set_view_flag( p_table_name => 'EMP2');
    -- this will show you the current value of the context variable
    SELECT sys_context( 'VIEW_CTX', 'TABLE_NAME' ) FROM DUAL
    -- this is the view definition - it does a UNION ALL of the three queries but only one will actually return data
    CREATE VIEW THREE_TABLE_EMP_VIEW AS
    select * from emp where 'EMP' = sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    union all
    select * from emp1 where 'EMP1' = sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    union all
    select * from emp2 where 'EMP2' =  sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    -- first time - no data since context variable hasn't been set yet
    SELECT * FROM THREE_TABLE_EMP_VIEW
    -- get data from the EMP table
    exec set_view_flag( p_table_name => 'EMP' );
    SELECT * FROM THREE_TABLE_EMP_VIEW
    -- get data from the EMP2 table
    exec set_view_flag( p_table_name => 'EMP2');
    SELECT * FROM THREE_TABLE_EMP_VIEW
    For your use case you just have to call the context procedure whenever you want to switch tables. You can union all as many queries as you want and can even put WHERE clause conditions based on other filtering criteria if you want. I have used this approach with report views so that one view can be used to roll up report data different ways or for different regions, report periods (weekly, quarterly, etc). I usually use this in a stored procedure that returns a REF CURSOR to the client. The client requests a weekly report and provides a date, the procedure calculates the START/END date based on the one date provided and sets context variables that the view uses in the WHERE clause for filtering.
    For reporting it works great!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SELECT statement in FROM clause - syntax help

    Hi,
    I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.
    I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):
    *I leave the INTO itab clause out, since I only want to demonstrate the functionality
    I am trying to get.
    <b>SELECT</b> tableOne~someField
    <b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField
                                         <b>FROM</b> tab
                                         <b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo
    <b>WHERE</b> tableOnesomeField > tableTwosomeField
    like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?
    thanks and regards
    Baran

    sorry i am not enough familiar with sub queries but some error i can see which i will state here.
    1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.
    like this
    SELECT * FROM SFLIGHT
        INTO WA
        WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
    2> you cannot specify field name without into clause either you have to use
    select *  or select f1 into tab-f1  like this...
    but if you are using select * without into you have to define
    tables : dbtab.
    selec * from dbtab. like that.
    regards
    shiba dutta

  • SQL Subquery in FROM clause

    Hi,
    some of my complex extractions that I am currently working on require nested SELECT statements. As far as I can see OpenSQL only supports subqueries in the WHERE clause, not in the FROM clause. Is this assumptions correct or is there a way around it? I have managed to use Native SQL for these nested expressions but the preference of the client is to use OpenSQL.
    Any ideas?
    Thanks,
    Tobias

    Hi
    In from clause you can use join.
    You can read data from more than one database table in a single SELECT statement by using inner or left outer joins in the FROM clause.
    The disadvantage of using joins is that redundant data is read from the hierarchically-superior table if there is a 1:N relationship between the outer and inner tables. This can considerably increase the amount of data transferred from the database to the application server. Therefore, when you program a join, you should ensure that the SELECT clause contains a list of only the columns that you really need. Furthermore, joins bypass the table buffer and read directly from the database. For this reason, you should use an ABAP Dictionary view instead of a join if you only want to read the data.
    The runtime of a join statement is heavily dependent on the database optimizer, especially when it contains more than two database tables. However, joins are nearly always quicker than using nested SELECT statements.
    thanks
    jagan

  • Record Group and From-Clause Datasource

    I need to do several complex queries (read-only) for my form. Original I used From-Clause datasource but, as the requirement changed, there are some limitations. I would rather no do anything dynamically if as all possible because there are over 20 such queries which makes the code difficult to maintain. I wanted to be able to reference block items in the query.
    I'm thinking about using Record Group query instead. What are the differences in capability between Record Groups and From-Clause Datasource?
    Thanks.
    Clayton.

    Thanks.
    That's exactly the problem I have. I don't want to use LOVs so I've been thinking about how to visualize the record group data using data blocks. Perhaps I'll just go with dynamically building the From-Clause.
    I've looked into stored procedure based blocks a bit; it was confusing for me. Are the stored procedures stored in the database or are they defined in the form?

  • Getting from clause query to work right?

    Hello, me again :) waves
    I am at a point now in my application where I need to base a block on a join. I have played around with Forms and used some very simple queries.
    As an example, consider these this SQL:
    select users.user_name, users_info.email from users, users_info where users_info.users_id = users.users_id
    this should return a username and an email address.
    Now, when I add this to a block, set the block's type to "from clause query" and create a canvas/frame/textboxes for the output it doesn't work. I try to "enter query"/"execute query". I get an FRM-40505 error (unable to perform query). I have defined all the columns in the blocks "query data source columns" property.
    I have searched through all the Developer books we have here as well as this forum. I would like to not have to create a view in the database for every little screen I need to make :(
    Ideas?

    The Database Item names in the block should match with the column names in the query. I think we don't have to set query data source columns property. So try creating a new block without this query data source columns property and with this from clause query and see if it works or not ?
    Partha
    null

  • Is there a way to use dynamic built string in the "from" clause

    Hi all, im having one problem and now, im not sure how to solve it easily at all... :) Is there someone that would be so kind and put a eye on it? ..thx
    I have plsql proc, in which i have a list of table_names. For each of that table i need to run a query that will retrieve me a list of values and for each of that value i need to do something.
    If i can be more specific about the problem -> each of that table is built as key_column, value_columns, day,starttime. For a key per table there are 4 records per hour - every quarter. Im truncating those quarters to full-quarter (minutes => 0->14 = 0min; 15->29 = 15min, 30->44 = 30, 45->59=45)
    example
    i get for one key and specific hour four records at 15:01;15:16;15:31;15:46 => i truncate em to 15:00;15:15;15:30;15:45..Sometimes there is a problem with the tool that is generating those data for me, and one quarter could be moved a little - so i get data like 15:01;15:16;15:29;15:46 => after i truncate the times i get duplicates in second quarter. It also can happen like this : 23:00; 23:14; 23:29; 23:44; 23:59 => totaly bad => cos the last one supposed to be as 0:00 next day, ..and 23:14 as 23:15...So...that was a problem - and solution -> i wanted to create plsql that will find those hours in each table i ve defined, and for each problem hour i make some fixes - update the bad time ...
    ..and i have problem - can i put an dynamic built table_name in the "from" clause?
    example how i wanted to do that:
    declare
         type t_objectName     is table of varchar2(030) index     by pls_integer;
         l_tableName              t_objectName;
    begin
    l_tableName(1) := 'tmphlrgl';
    l_tableName(2) := 'tmprcfgl';
    l_tableName(3) := 'tmprcfbs';
    l_tableName(4) := 'tmpvlrgl';
    for i in (select evtime from (select day,trunc_quarter(evtime) evtime,m_id from l_tableName(i) group by day,trunc_quarter(evtime),m_id having count(*)>1) order by evtime) loop
    --some other conditions and the update...
    end loop;
    end;
    /I cannot use the l_tableName(i) for FROM ...get an error...I was thinking to build it as dynamic sql and execute immediate into some kind of object that can store mutliple lines, from which i would in the FOR cycle get the data...But im not sure if this could be done in plsql...
    thanks for your time and help..
    d.

    declare
    c sys_refcursor;
    begin
    for i in 1..4 loop
    open c for 'day,trunc_quarter(evtime) evtime,m_id
    from ' || l_tableName(i) ||
    'group by day,trunc_quarter(evtime),m_id having
    count(*)>1) order by evtime';Just to high light SELECT is missing that all
    OPEN c FOR ' SELECT day,trunc_quarter(evtime) evtime,m_id
              FROM' || l_tableName(i) ||
    'GROUP BY day,trunc_quarter(evtime),m_id  HAVING  count(*)>1)   ORDER BY evtime';

  • How do I display data from Multiple Queries in a spreadsheet?

    I am running Oracle forms 10g as a kicker to export a report (rdf 10.1.2.0.2) to PDF or Excel Spreadsheet - User's choice.
    Doesn't matter if I have desformat = SPREADSHEET, DELIMITEDDATA, or DELIMITED; I still get only the first query displayed when I run in spreadsheet format.
    How do I display data from Multiple Queries in a spreadsheet? Is this possible?
    Thanks in advance!

    Hi adam,
    did you search the forum? You will find a lot of threads handling the problem of Excel file access.
    In short: you need to use ActiveX (the RGT also uses ActiveX under the hood)!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?

    For some reason, I am trying to use a variable name containing the actual table name in the from clause and it won't allow me. I keep getting the error saying I need to declare the variable I'm using eventhough I've used it in another statement that is not the FROM clause.
    Example
    SELECT count(col1), sum(col2)
    FROM v_table_name;
    v_table_name was declared as:
    v_tablename VARCHAR2(20);
    v_tablename := real_table_name;
    Is it not allowed to use variables in the FROM clause or am I missing something here?

    You can use the Forms "From Clause Query" as the datasource for the data block. Then you can change the QUERY_DATA_SOURCE_NAME using set_block_property, so you can use any SQL statement you like. Of course you must name/alias the columns in a consistent manner so that the number of database items on the block matches those being queried.

  • Can't get query to work.  table alias in subquery in FROM clause

    How can I rearrange this query to work?
    SELECT
                               TO_CHAR(dt.date_time, 'YYYY-MM-DD') start_date,
                                       (SELECT COUNT(*) FROM
                                            (SELECT DISTINCT a.non_asp, a.start_time, a.end_time
                                                  FROM appointments a
                      WHERE  a.start_time >= dt.date_time AND a.start_time < dt.date_time + 1
                                       ) num_overlap
                             FROM
                                  table(times_pkg.between_times(TO_DATE('2010-05-30'),
                                             TO_DATE('2010-07-03'), 60*24, 'Y')) dtbetween_times is a table function that returns times at given intervals.
    I am trying to get a count of distinct (non_asp, start_time, end_time) sets that fall on each day.
    However, it doesn't recognize dt.date_time in the FROM clause.

    Hi,
    A sub-query can be correlated only to its immediate parent. You're trying the correlate the SELECT DISTINCT sub-query to its grandparent.
    You can re-write the sub-query as a join, like this:
    SELECT  TO_CHAR(dt.date_time, 'YYYY-MM-DD') start_date,
         a.num_overlap
    FROM     table ( times_pkg.between_times ( TO_DATE('2010-05-30'),
                               TO_DATE('2010-07-03'),
                               60*24,
                               'Y'
               ) dt
    JOIN    (
           SELECT    start_time,
                    end_time,
                  COUNT (DISTINCT non_asp)     AS num_overlap
           FROM         appointments
         )  a         ON  a.start_time         >= dt.date_time
                  AND a.start_time         < dt.date_time + 1
    ;You could also eliminate the extra level between the SELECT DISTINCT sub-query and the main query by using SELECT (DISTINCT ...).

  • Exception: DBD, [Microsoft][ODBC Excel Driver] Syntax error in FROM clause.

    Dear experts,
    I'm trying to create an universe linked to an Excel File.
    I've created the ODBc connection and the DNS Data Source and inserted the table (table name RAC$) in the Universe. however, when I try to map each table field in the universe's Objects I'm getting this error message:
    "Exception: DBD, [ODBC Excel Driver] Syntax error in FROM clause.State:37000".
    I've tried to rename the table, inserting square brackects and also add new parameters to the universe («Transactional Available = "Yes"» and «Delimited Identifier = "Yes"») but still no solution to my problem.
    Any advice, tip or trick?
    Thank you. My best regards.
    Inês Santos

    Hi Ines,
    Thanks for sharing how you resolved this! I will bookmark this so that I can find it when I will likely need it!
    Bill
    Sorry I don't know how to make the accent circumflex! Or is that what you call it? On top of the e?
    Edited by: wavery on Jun 11, 2010 12:07 AM
    Edited by: wavery on Jun 11, 2010 12:09 AM

  • Error in FROM clause

    hi,
    ok i have a piece of code which looks like
    ResultSet rs = stmt.executeQuery("SELECT OrderDate, ProdNumber, Quantity, Price, OrderNumber FROM Order WHERE EmailAddress='" + email + "'");
    when i execute it... i get following error
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
    i don't think there is any problem with syntax...
    thanx in advance

    Hey the escape character in java is \ you need to use that to escape the property of " for eg you will write like this ResultSet rs = stmt.executeQuery("SELECT OrderDate, ProdNumber, Quantity, Price, OrderNumber FROM Order WHERE EmailAddress= "\""+ email + "\"");
    try this and let me know if it works

  • Sequence of tables in from clause and sequence of "where clause" conditions

    Is Sequence of tables in "From Clause" and sequence of "where clause" conditions matters in 10g for performance?
    Edited by: user6763079 on Jun 1, 2011 3:33 AM

    user6763079 wrote:
    Is Sequence of tables in "From Clause" and sequence of "where clause" conditions matters in 10g for performance?In general it does not matter.
    It could matter if the Rule Based Optimizer (RBO) is used. However this RBO is only used if enforced by a hint or if no table statistics are collected. Starting from 10g the table statistics are automatically selected by a regular database job. So in general the CBO would be used.
    The CBO will consider different access paths. If the number of tables is low enough, then all possible combinations are considered and the order does not make any difference.
    Edited by: Sven W. on Jun 1, 2011 4:00 PM

Maybe you are looking for