FROM CLAUSE as datasource

HI All,
I am trying to create a block that base on FROM CLAUSE
as datasource. But I need to reference several control block items as the criteria of the select statement.
But when I execute the query, the system keep saying that 'Invalid column name'.
I want to know is that I cannot reference block item in the 'from clause query select statement' ?
Thanks!!!

thanks!
I am ok now, I want to change the where clause dynmically.
I dynamiclly change the 'Datasourse Name' property in order to achieve this.
Thanks again!

Similar Messages

  • How to use From clause as a block datasources

    Hi,
    I want to know how to use from clause as a block datasource.
    Could anyone give me an example to do that? I couldn't find it
    in the help file.
    I sincerely ask someone help me.
    Many thanks
    Diana

    Diana,
    I presume you are getting a "FRM-40505: error unable to perform
    query" when you try to execute query. I suggest you select the
    "Display Error" item from the "Help" menu to see the query that
    Oracle is generating. If the query that Oracle generates as a
    result of your "Query data source name" is not formed correctly,
    you will get the FRM-40505 error.
    Copy and paste the query that is displayed into SQLPLUS and test
    to see what happens when you try to execute the query from
    SQLPLUS. That will give you a better idea of what the cause of
    the problem is.
    From your example, a query that works should look like "select
    c_no from (select c_no from books)".
    Keep in mind that for blocks based on FROM clause, the query that
    produces the data is of the form :
    SELECT <all columns in the block>
    FROM <select statement entered in the "Query Data Source Name"
    blockproperty>
    The data source for the block is the select statement embedded in
    the from clause.
    Hope this helps.

  • 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?

  • 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.

  • Error in FROM clause (MS Access)

    I'm getting an 'error executing a database query.' The query
    is a simple
    <cfquery name="myquery" datasource="#application.dsn#">
    SELECT *
    FROM #url.table#
    </cfquery>
    The debugging info i get is as follows:
    SELECT * FROM Order
    VENDORERRORCODE -3506
    SQLSTATE 42000
    It also states the error is in the FROM clause and only
    happens when url.table is Order, not the other table names. I know
    the order table exists because i get a nonexistent table name error
    when url table is a bogus table name. This implies that
    it knows the order table exists but says there's an error in
    the FROM clause. The query is successful on all the other tables in
    my db (MS access, i'm using the access driver without unicode). Any
    ideas?

    order is a reserved word...you'll need to escape it using
    brackets
    FROM [order]
    HTH
    Tim Carley
    www.recfusion.com
    [email protected]

  • From Clause Query

    Designer Version 6.5.95.4.8
    Configuration: 4.0.12
    Release 4.10
    Database 10g
    Forms [32 Bit] Version 6.0.8.25.2 (Production)
    Can someone help me with From Clause query in Designer?
    Designer Help files do not seem to cover this in depth.
    Here is what I did so far.
    1. Created module component
    2. Set Datasource Type to Query
    3. Code to set the query at run time:
          GO_BLOCK('LINK_DTL');
          CLEAR_BLOCK(NO_VALIDATE);
          vFromClauseQuery := '(SELECT DISTINCT p_code, e_code '||
                               'FROM code_table '||
                               'WHERE L_YEAR = '||:LINK.l_year||' AND L_SEQ = '''||:LINK.l_seq||''')';
          SET_BLOCK_PROPERTY('LINK_DTL',QUERY_DATA_SOURCE_NAME,vFromClauseQuery);
          DO_QUERY;   
    Also I created unbound columns :p_code and :e_code for the block, to receive the results from the query (is that the correct way to do it?)
    When I run the form, my block is empty, and if I open the form in form builder, the block that I had set to have datasource of "query" has datasource type of "table" ???
    Thanks

    Bind variables cannot be referenced in from clause query (this is a bug/enhancement 767062).
    But, in PRE-QUERY trigger we can write built-in
    SET_BLOCK_PROPERTY (block_name, QUERY_DATA_SOURCE_NAME, value);
    For example:
    DECLARE
    l_deptno dept.deptno%TYPE := 50;
    l_from_clause VARCHAR2 (1000);
    BEGIN
    l_from_clause :=
    '(SELECT deptno, dname, loc FROM dept WHERE deptno < ' || l_deptno || ')';
    SET_BLOCK_PROPERTY (:SYSTEM.TRIGGER_BLOCK, QUERY_DATA_SOURCE_NAME, l_from_clause);
    END;
    Regards,
    Zlatko Sirotic

  • FROM Clause query data source type

    i do i get the result set of a FROM Clause datasource into an item.

    A FROM clause may be used as the datasource for a data block. A FROM clause is a feature of the Oracle8 Server that allows you to nest a SELECT statement in the FROM clause of a SELECT statement. A FROM clause is a valid query block datasource, but it is not a valid DML block datasource. The value returned from a FROM clause is a subset of records from the original query.
    FROM clauses are used to perform joins, lookups, and calculations without having to create a view on the server. FROM clauses can also be used to prototype views and to increase performance.
    Using a FROM clause as a block datasource is similar to using an updateable join-view as a block datasource. However, a FROM clause provides more control, because the presence of a DBA is not required to define the view. You should note that the FROM clause produces results that are identical to an updateable join-view from the client side, but that there is no defined view on the server.
    My question has not been answere and i hope the above copies explanation from forms6i documentation will help understand the question better.
    Please Advise

  • 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';

  • 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

  • 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

  • Curious about this From clause in Oracle XE

    SQL view of query Builder gives the following:
    select     "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
         "EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
         "EMPLOYEES"."LAST_NAME" as "LAST_NAME"
    from     "EMPLOYEES" "EMPLOYEES"
    Why does the from clause showing "EMPLOYEES" "EMPLOYEES"?
    In the SQL Commands of the SQL the folowing query
    select     "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
         "EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
         "EMPLOYEES"."LAST_NAME" as "LAST_NAME"
    from     "EMPLOYEES
    gives the same result and so does
    select     "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
         "EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
         "EMPLOYEES"."LAST_NAME" as "LAST_NAME"
    from     "EMPLOYEES" "EMPLOYEES"
    What is the significence of the second "Employees" in the FROM clause.

    Other interesting feature is the double quotes
    although the one above works as well.
    Why is this?Habit.
    Some developers come from environments that support mixed case identifiers (table and column names). These developers sometimes go out of their way to force Oracle to use mixed case identifiers, and that requires double quotes.
    So Oracle seems to have gotten into the habit of surrounding all identifiers (coming from generated code) with double quotes to keep these developers (who usually have other porting issues anyway) from having to trace those identifier issues.

Maybe you are looking for