How to avoid using schema_name in select statements

Hello
I am in the process of developing a 3-tier database application with Delphi, using Oracle database server. When I try to to execute the following code in a query on the client application(with a logged user who has been granted select on that table):
SELECT C1,C2
FROM TABLE1
WHERE ((C3 = :P1) OR (C3 IS NULL))
AND (C4 = :P2)
ORDER BY C5
it raises an "ORA-00942: table or view does not exist" exception. The table exists, the user has the necessary grants, but it still doesn't work. When I put the actual schema_name before the table name it starts to work(like this):
SELECT C1,C2
FROM SCHEMA1.TABLE1
WHERE ((C3 = :P1) OR (C3 IS NULL))
AND (C4 = :P2)
ORDER BY C5
What am I doing wrong?

To explain the reason for the solutions suggested.
The problem is scope. Just like having a constant in another Delphi unit which is what you want to reference in the current unit.
You refer to an object. Oracle scope resolution first looks in the current schema for the session. If it does not find the object there (as a table/view/synonym/etc), it looks in the public context (public synonyms). It does not traverse any other schemas as that would be a very dangerous and inefficient thing to do (e.g. imagine referring to EMP and you have access to EMP tables in JOE's and SCOTT's schemas - which EMP is the real EMP?).
You can change the current schema for scope resolution. E.g. you're signed in as schema SCOTT. You issue an alter session set current_schema=hr_system. Now the default scope is HR_SYSTEM and no longer SCOTT. However, you're SCOTT privs are still applicable.
Alternatively you can use synonyms or public synonyms. The latter should however not be used for application objects. Public should only be used for generic objects applicable across all application schemas.

Similar Messages

  • How to avoid the below nested select statement

    Please any one help me how this select statemet is working and      how to avoid the nesetd select statement .
    if we avoid below nested , does it improve performace ?
    select field1 field2                                  
               into table w_feeds                                 
               from ZTable as t                         
               where field2 in r_feedf1                       
               and  POSITION_POSTDT =                           
               ( SELECT MAX( position_postdt ) FROM zTable 
                      where position_postdt le r_pdate-high    
                      and   field1 = t~field1 ).
    Thanks in Advace.

    Hi,
    Instead of nested query go for two separate queries. I see you are querying on the same table...so better go by this approach
    select field1 field2 POSITION_POSTDT
    into table w_feeds
    from ZTable
    where field2 in r_feedf1.
    Remove the where condition on POSITION_POSTDT
    Sort the table w_feeds by POSITION_POSTDT  Descending; So you will get data pertaining to Max Position_Postdt.
    Finally delete the other entries which are not Max.
    This will enhance the performance over the nested query.
    Regards
    Shiva
    Edited by: Shiva Kumar Tirumalasetty on Apr 27, 2010 7:00 PM
    Edited by: Shiva Kumar Tirumalasetty on Apr 27, 2010 7:00 PM

  • Using procedure in SELECT statement

    I have a select statement that currently uses 4 functions to receive necessary values. All the functions are recursive and returns values from the same row.
    What I would like to do is replace these for function calls with 1 procedure. Does anybody know if it possible to use a procedure in this way inside a select statement?
    If so, do you have the syntax for doing this?
    E.g
    SELECT
    Mdbrd_Pkg.calculate_fixed_charge_fn(in_rc_id, ap.CONFIGSET_ID) AS FIXED_CHARGE,
    Mdbrd_Pkg.calculate_charge_rate_fn(in_rc_id, ap.CONFIGSET_ID) AS CHARGE_RATE,
    Mdbrd_Pkg.tax_liable_fn(in_rc_id, ap.CONFIGSET_ID) AS TAX_LIABLE,
    Mdbrd_Pkg.charge_unit_fn( in_rc_id, ap.CONFIGSET_ID) AS CHARGEUNIT_ID
    FROM .....

    This cannot be done. The part of the function used in the SELECT statement is the return value: procedures don't have return values (that's what makes tham procedures and not functions).
    Obviously I don't know what your code does, but you should consider putting them into a single function that returns a TYPE with four attributes and then using the TABLE() function to cast them into something you could reference in the FROM clause of a correlated sub-query. Sounds a bit messy though.
    Do these functions actually select data? Where does the recursion fit in?
    Cheers, APC

  • How to call user fuction in select statement.

    hi,
    i am facing some problem.How to call user functions in select statement.please send me answer with example.
    Thanks
    Gopal

    Locations to Call User-Defined Functions
    • Select list of a SELECT command
    • Condition of the WHERE and HAVING clauses
    • CONNECT BY, START WITH, ORDER BY, and GROUP
    BY clauses
    • VALUES clause of the INSERT command
    • SET clause of the UPDATE command
    Restrictions on Calling Functions from SQL Expressions
    To be callable from SQL expressions, a user-defined
    function must:
    • Be a stored function
    • Accept only IN parameters
    • Accept only valid SQL data types, not PL/SQL
    specific types, as parameters
    • Return data types that are valid SQL data types,
    not PL/SQL specific types
    • Functions called from SQL expressions cannot
    contain DML statements.
    • Functions called from UPDATE/DELETE statements
    on a table T cannot contain DML on the same table
    T.
    • Functions called from an UPDATE or a DELETE
    statement on a table T cannot query the same table.
    • Functions called from SQL statements cannot
    contain statements that end the transactions.
    • Calls to subprograms that break the previous
    restriction are not allowed in the function.
    jeneesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Why I Can't use procedure in select statement

    Why I Can't use procedure in select statement

    We can use function in select statement but we couldn't use procedure with one out parameters in select statement... You can use Function because they are designed for this but procedure are not. Functions can return value (without OUT parameter) which can be used in SELECT whereas procedures do not have such concept. As you can see in the above post you can not call even functions also if it has any out parameter.
    I have just trying to use procedure in select statement ..for this I require technical answer..The technical answer is because conceptually procedure is for doing set of operation, performning DMLs on the tables , whereas functions are for processing and producing a single result. Functions are basically for not using INSERT/UPDATE/DELETE in it. That is the reason they are allowed to be used in SELECT because conceptually they are not supposed to do any data changes.
    Regards,
    Avinash

  • How to put OR clause in SELECT statement

    Hi
    How to put OR clause in SELECT statement to return number_first/number_last to match records from another table's column.
    <pre>
    SELECT
    a.id ,
    flat_number ||' '|| a.number_first||' '||a.street_name||' '||a.suburb address1,
    apt_no ||' '|| street_no||' '||b.street_name||' '||b.suburb address2
    from
    a ,
    b
    where b.street_name = a.street_name
    AND b.SUBURB = a.SUBURB
    AND b.STATE = a.STATE
    </pre>
    Thsi will return this as exact match.
    ADDRESS 1
    12 TAMAN TENANG A ORCHARD 3142     
    10 RAMA YISHUN 2095
    ADDRESS2
    12 TAMAN TENANG A ORCHARD 3142     
    10 RAMA YISHUN 2095
    However this only matches number_first.
    How can I get the query work that it will match both number_first and number_last (table b)in address 1 to match street_no in address2 ( table b).My oracle version is 10GR/2.

    Hi, I have a hard time understanding your request, and below is what I thought you want:
    SELECT
        a.id ,
           flat_number ||' '|| (decode(b.street_no, a.number_first, a.number_first, a.number_last, a.number_last)||' '||a.street_name||' '||a.suburb  address1,
             apt_no ||' '|| street_no||' '||b.street_name||' '||b.suburb address2
          from
                 a ,
                 b
                where          b.street_name = a.street_name
                 AND            b.SUBURB      = a.SUBURB
                AND            b.STATE       = a.STATE
                AND  (B.street_no=a.number_first OR b.street_no=a.number_last);Not tested.
    Also, since your B.street_no will be either a.number_first OR a.number_last, you could replace
    (decode(b.street_no, a.number_first, a.number_first, a.number_last, a.number_last) with just b.street_no.
    Edited by: PhoenixBai on Aug 26, 2010 11:33 AM

  • I got an iPhone 4 while I was living in Japan. How can I use it in the states now that I live here?

    I was using an iPhone 4 while I was living in Japan. How can I use it in the states now that I live here? It is a perfectly good phone and I don't want to use it only as an iPod and camera.

    That's one option. The other is to sell it (you can probably get close to what you paid for it) or trade it in and get a new unlocked phone directly from an Apple store. That way you can use it in the US, and also in Japan when you return there.

  • Using Cursor in Select statements? How to do this?

    I am getting an error whilt passing a cursor to a select clause:
    SELECT dbms_xmlquery.getXML('select deptno, dname, '||
    'cursor(select empno, ename, sal from emp e where e.deptno = d.deptno) employees '||
    'from dept d where d.deptno in (10, 20)')
    FROM dual;
    DBMS_XMLQUERY.GETXML('SELECTDEPTNO'||'CURSORIS(SELECTEMPNOFROMEMPEWHEREE.DEPT=D.
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00923
    : FROM keyword not found where expected
    </ERROR
    THIS IS DUE TO THE CURSOR AND ITS FROM STATEMENT?
    CAN ANY ONE PLEASE GUIDE AS TO HOW TO USE CURSORS IN A SELECT STATEMENT PLEASE?

    Another duplicate thread. See my response Select CLAUSE error using CURSORS & XSU.Please SEE..
    Cheers, APC

  • Checkboxes: How do you use them to select geometries for display, MapViewer

    Dear all
    I am working in Oracle 10.2 and using PL/SQL. I am trying to create a procedure that generates a list of spatial layers, based on those currently contained in the database, which uses checkboxes, so that users can select which layers to display.
    Once the user has made his choices and the results are submitted, the chosen layers are displayed through MapViewer. Currently the procedure, which is still being developed, is as follows:
    PROCEDURE MAPLIST AS
    CURSOR curmaplist IS
      SELECT spatial_map_name
             spatial_map_id
             geom
       FROM spatial_map_table;
      varmaplist curmaplist%ROWTYPE;
       varchecked VARCHAR2(32767);
    BEGIN
    FOR varmaplist in curmaplist LOOP
      htp.print('<FORM>
                  <UL>
                   <LI>
                    <LABEL FOR="SM_ID||
                                curmaplist.spatial_map_id||">
                     <INPUT type="checkbox"
                            id="SM_ID||
                                curmaplist.spatial_map_id||"
                            name="SM_ID||
                                  curmaplist.spatial_map_id||"
                            value="MAP TITLE: ||
                                   curmaplist.spatial_map_name" />
                    </LABEL>
                   </LI>
                  </UL>
                 </FORM>'
      EXIT WHEN curmaplist%NOTFOUND;
       END LOOP;
    END;I am not sure how to incorporate the checked element and then make use of it. Regarding subsequent use, I wondered if an IF statement could be used.
    IF VARCHECKED = 'CHECKED' THEN...after this MapViewer XML is added, with the select statement making use of the cursor. For example:
    select curmaplist.geom
    from geg50160.spatial_map_tableFor the checked part itself, I have found the following Oracle code in Chapter 11 of Oracle Database Application Developer’s Guide - Fundamentals 10.2.
    CREATE OR REPLACE PROCEDURE handle_checkboxes ( checkboxes owa_util.ident_arr )
    AS
    BEGIN
    FOR i IN 1..checkboxes.count
    LOOP
    htp.print('<p>Checkbox value: ' || checkboxes(i));
    END LOOP;
    END;
    /However I am not certain how I would incorporate that into my code. I take it i refers to the checkbox value. I've read that .ident_arr is an array which can hold multiple values but if so I am also not sure why checkboxes are counted.
    Kind regards
    Tim

    Hi GKaiseril,
    Thanks for your reply.  That's what I'm attempting to do, but I'm largely trying to "borrow" on-line JavaScript (see below) & modify for my PDF Form, w/ rudimentary knowledge gained while surfing the web.  The Form has 30 checkboxes that I want to limit users to a max. of 4.
    So any add'l scripting tips would be most appreciated.
    Thanks!
    var NewCount = 0
    getField("Check_Box1").value === "Yes"
    {NewCount = NewCount + 1}
    getField("Check_Box2").value === "Yes"
    {NewCount = NewCount + 1}
    getField("Check_Box3").value === "Yes"
    {NewCount = NewCount + 1}
    getField("Check_Box4").value === "Yes"
    {NewCount = NewCount + 1}
    getField("Check_Box5").value === "Yes"
      {NewCount = NewCount + 1}
    if (NewCount == 4)
    app.alert(“Pick Just Four Please”); return false;

  • Using TMVL in Select Statement

    Dear All,
    Is the usage of TMVL in Select Statement valid?
    *SELECT(%VAR_YEAR%, YEAR, TIME, ID = TMVL(-12, %TIME_SET%))
    I don't think I manage to get this statement running.
    Thanks,
    YL

    Thanks All.
    My requirement is:
    Copy from Source to Destination using script logic:
    Package Selections:
    Category : Forecast
    Time : 2025.12
    Version : 2025
    Source
    Dimension Category : Plan
    Dimension Time : 2025.12
    Dimension Version : 2024
    Destination
    Dimension Category : Forecast
    Dimension Time : 2025.12
    Dimension Version : 2025
    And question is how to derive Version 2024 which is 2025 - 1, without using a specific property for it, i.e. Previous Year?
    Thank you very much.
    Best regards,
    Yen Li

  • How user variable table names in select statement

    Dear all,
    I have three table gp1,gp2,g3. i want user variable table in sql query
    for example at oracle forms have a list table showing table names gp1,gp2,gp3
    at form i want user this query
    select gpno from :table where gpno=120;
    how i can specify table name Dynamicly in select query
    Thanks

    Forms_DDL is a one-way street: You can only pass DDL commands TO the database; you cannot get data back using Forms_DDL.
    Exec_SQL is the Forms package that enables dynamic sql within a form. But to retrieve data, you have to make a Exec_SQL call for every column in every row. So it is not a good thing to use, either.
    The ref cursor method should work. You could also retrieve the data into a record group using populate_group_with_query -- it also enables dynamic data retrieval.
    But if you already know you have three distinct tables and you know their names, I would keep it simple and just write three sql select statements.

  • How display number of row in select statement

    How can I display number of row in select statement?
    Table
    data1 data2
    xxx ccd
    wss qwe
    qws uij
    I need get from SELECT statement:
    1 xxx ccd
    2 wss qwe
    3 qws uij

    user13734495 wrote:
    Thank you from answer.
    Statement
    select rownum rn, data1, data2 from table
    is good.
    And what have I do went I use
    select rownum rn, data1, data2 from table order by data1
    and I get
    3 qws uij
    2 wss qwe
    1 xxx ccd
    I need
    1 qws uij
    2 wss qwe
    3 xxx ccdhence the importance of describing the complete problem.
    select
      rownum,
      data1,
      data2
    from(
      select
        data1,
        data2
      from
        table
      order by
        data1)

  • Want to use Index in Select statement

    Hi,
    I want to use the index tha is created for LIPS table for creation date. I want to use that INdex in the select statement to get the data from that table. Any one can tell me how can I right the select statement in report?
    thanks.

    Like I mentioned earlier, the optimizer is smart enough to choose the correct index based on the WHERE clause.  So if you created an index on field ERDAT for LIPS and your SELECT statement is like so.....
    Select ERDAT WERKS MATNR
              from LIPS
                          into table Itab
                                    Where erdat in s_erdat        "< - ERDAT First in WHERE Clause
                                        and werks in s_werks
                                        and Matnr in s_matnr.
    Then the optimizer will choose your index to use to access the data.  You can see these if you would do an SQL trace over your program and use the "Explain" button on ST05.  It will tell you which index it used and why.
    There is no need to use HINTs to force the use of the index.
    Regards,
    Rich Heilman

  • How to avoid using constants ?

    Hello,
    I am starting a new project and I am thinking of a way to avoid using constants.
    For example, in a report, it selects all the order with types ZLN and ZLB.
    I know that I have several possibilities :
    - hard code it in the program (using constants which I want to avoid)
    - create a specific table with all the types that I want to select (this may be the best solution but it can be very long -> too much table to create)
    - put the parameter in the selection screen (but then we have to put default values which come back to the same problem)
    So, I didn't found any perfect solution, Do you know what is the method recommended by SAP ?
    What kind of technics did you use in you projects ?
    Thank you for your help !

    Hi Friend ,
    As you taught , there are  multiple  ways to handle the constants in the program.
    But finally time & efficency matters alot  .
    so my  idea would be  i will  list all the constant & get the quick understanding of the constant type's.
    For example : Order type is Customizing data  which will maintained  by Fun.Consultant  , so i will give work for him to maitain the Varient against  Order type in the TVARC table .so that  in the program  i will declare one order type vraible  under atselection-screen event i will write select Query to get the vaule from the TVARC table which will be maintaine . we can write the execption also with sy-subrc <> o.if it is not maintianed .so far all customizing data fields  this would be the best way for constants maintaining outside your program  .
    Similarly if any system constants then we can get it in runtime  with SYST table parameters .
    if there are any  ABAP Program Constants  ( Titles,labels ,case condition parameters,ect) maintain in the tprogram ext elements , or you can generically maintain a Utility class where you can create an attribute  so that whereeven you want you can reuse the same  .
    Regards,

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

Maybe you are looking for

  • ITunes 6.0.1.3 smart playlist and rating problem

    I noticed my iPod playlists don't update live anymore, so I checked their settings in iTunes and found that, for some reason, there are no stars listed in the smart playlist. I deleted them all and tried to start fresh. I click File > New Smart Playl

  • In 2008 R2, I get Object doesn't support property or method PollResizeImages

    This is when I run a report from a reportviewer control to reporting services.   Another symptom is that images get cropped but if I refresh page cropping doesn't occur I have this version of SQL server 2008 R2 Microsoft SQL Server 2008 R2 (SP1) - 10

  • Can i host a site on mac os x server?

    hellow guys i need some help, this is my site http://www.inauzwa.com, can i use the mac os x lion server to host this site? thank you regards arnold gabriel cofounder @ http://www.inauzwa.com

  • Connecting PowerBook to PowerMac

    I've heard there is a procedure for connecting a PowerBook to a PowerMac so that basically the PowerBook is an external hard drive for the PowerMac. What all is involved besides just hooking the firewire cable to each computer? TIA for your help.

  • MP3 CDs won't work in car stereo

    Hello. I've tried multiple burning tests with iTunes, Toast, and the Finder. I'm trying to get an MP3 CD to work in my 2007 Mazda 6 (five CD changer). The manual says it will read MP3 CDs, and I am burning MP3s... not AACs. When the CD is loaded into