Doubt regarding query and subquery

Hi guys,
if I run the following query :
SELECT NUM_OCORRENCIA, NUM_ENVOLVIDO FROM BO_VEIC_ACIDENTE BVA
WHERE BVA.NUM_OCORRENCIA = BE.NUM_OCORRENCIA
I get the following error message : ORA-00904: "BE"."NUM_OCORRENCIA": invalid identifier
because we dropped the column num_ocorrencia.
But if I run the same query as a subquery , like :
SELECT COUNT(BE.NUM_ENVOLVIDO)
FROM BO_ENVOLVIDO BE ,
BO_TIPO_ENVOLVIMENTO BTE
WHERE BE.ID_ENVOLVIMENTO = BTE.ID_TIPO_ENVOLVIMENTO
AND BTE.CODIGO IN ('0100','0200','0300','1302','1303','1304')
AND (BE.NUM_OCORRENCIA,BE.NUM_ENVOLVIDO) NOT IN (SELECT NUM_OCORRENCIA, NUM_ENVOLVIDO
FROM BO_VEICULO_ENVOLVIDO BVE
WHERE BVE.NUM_OCORRENCIA = BE.NUM_OCORRENCIA)
AND (BE.NUM_OCORRENCIA,BE.NUM_ENVOLVIDO) NOT IN (SELECT NUM_OCORRENCIA, NUM_ENVOLVIDO
FROM BO_VEIC_ACIDENTE BVA
WHERE BVA.NUM_OCORRENCIA = BE.NUM_OCORRENCIA)
AND BE.NUM_OCORRENCIA IN (SELECT NUM_OCORRENCIA FROM BO_OCORRENCIA_POLICIAL WHERE COD_TIPO_OCORRENCIA = 1)
AND BE.NUM_OCORRENCIA = '2006-000000406' ;
no error message are displayed. So I want to understand why Oracle get this behavior in this query.in the last query i got the result ' 0 ' . why Oracle didn´t showed me the same error in the second option ?
thanks,
Felipe

I think you need to get some coffee ;)
It's a scope issue the table alias BE does not exist in the first query but does in the second so it can be referenced in the subqubquery.
Hi guys,
if I run the following query :
SELECT NUM_OCORRENCIA, NUM_ENVOLVIDO FROM
BO_VEIC_ACIDENTE BVA
WHERE BVA.NUM_OCORRENCIA = BE.NUM_OCORRENCIA
I get the following error message : ORA-00904:
"BE"."NUM_OCORRENCIA": invalid identifier
because we dropped the column num_ocorrencia.
But if I run the same query as a subquery , like :
SELECT COUNT(BE.NUM_ENVOLVIDO)
FROM BO_ENVOLVIDO BE ,
BO_TIPO_ENVOLVIMENTO BTE
E BE.ID_ENVOLVIMENTO = BTE.ID_TIPO_ENVOLVIMENTO
AND BTE.CODIGO IN
('0100','0200','0300','1302','1303','1304')
AND (BE.NUM_OCORRENCIA,BE.NUM_ENVOLVIDO) NOT IN
(SELECT NUM_OCORRENCIA, NUM_ENVOLVIDO
FROM
BO_VEICULO_ENVOLVIDO BVE
WHERE
BVE.NUM_OCORRENCIA = BE.NUM_OCORRENCIA)
AND (BE.NUM_OCORRENCIA,BE.NUM_ENVOLVIDO) NOT IN
(SELECT NUM_OCORRENCIA, NUM_ENVOLVIDO
ROM BO_VEIC_ACIDENTE BVA
WHERE
BVA.NUM_OCORRENCIA = BE.NUM_OCORRENCIA)
AND BE.NUM_OCORRENCIA IN (SELECT NUM_OCORRENCIA FROM
BO_OCORRENCIA_POLICIAL WHERE COD_TIPO_OCORRENCIA =
1)
AND BE.NUM_OCORRENCIA = '2006-000000406' ;
no error message are displayed. So I want to
understand why Oracle get this behavior in this
query.in the last query i got the result ' 0 ' . why
Oracle didn´t showed me the same error in the second
option ?
thanks,
Felipe

Similar Messages

  • Plz clear this doubt abt query and subquery

    hi
    can a sql statement display data from a table that is referred in it's subquery without including the table in the from clause..
    please give an example for this
    thank u
    rajiv

    Have you tried it yourself?
    It would be much quicker than waiting for a forum answer.

  • Small doubts regarding devices and permissions

    Hill all,
    Continuing with my experiences with Oracle 11gR2 and Solaris 11, i came up with some "small" doubts regarding the permissions and owners of the devices to be used as ASM diskgroups. I was able to install Grid and the database, both 11.2.0.3.0, in a single-instance configuration, but i had a small issue when creatind the diskgroup for the database data (+DATA). I created 3 devices (VirtualBox) to be used in the +DATA dg, and gave the the "oracle:dba" owner, with the permission 660. My doubts are:
    1) It wouldn't be more correct to make the owner of the device the user grid? (grid:dba)
    2) The permission 660 to the devices is the correct, or recommended permission? It did work with this permission.
    Thanks in advance.

    It depends on the user and group that runs the ASM instance. It can be oracle/dba, but can also be a different user, e.g. grid/asmadmin
    http://docs.oracle.com/cd/E11882_01/install.112/e22489/storage.htm#CHDFAGJD
    660 means rw. That should be ok. No other user/group than the ASM instance needs to access the devices.

  • Regarding Query and Logical database

    Hi All,
      I have one requirement to create a report which gives all selection fields of a query.I got the selection fields defined in the query,but some extra selection fields are coming from logical database,which query uses.These extra fields count is different for different queries using same logical data base.Please suggest me a solution.
    Regards
    Shibin

    Hi Jogeswara,
    Thanks for your inputs.
    But my question is, how can I filter the data which is being fetched by standard logical database. I cannot go inside the std. LDB and change internal tables of it. I tried coding in extras, but I think it works only if we want to add additional fields in output.
    At present, we are considering the option of creating a z LDB where we copy. std. LDB and also add the reqd. table which is not present in LDB.
    Is there any other option?
    Please provide your valuable inputs.
    Regards,
    Imran Kundan.

  • I was looking at the "Find my iPhone" app and I have a doubt regarding how it works for the macbook. In order to detect the location, the macbook should remain signed into iCloud. What if the thief logs out of iCloud. Would we able to locate the macbook?

    I was looking at the "Find my iPhone" app and I have a doubt regarding how it works for the macbook. In order to detect the location, the macbook should remain signed into iCloud. What if the person who has stolen my macbook logs out of iCloud.
    It should work fine for iPhone/iPad because we can enable "Restrictions" to prevent the user from signing out of iCloud. Do we have simialr settings for the macbook?
    Thanks,

    If it's not on the device list, it indicates that someone has gone to Find My iPhone on icloud.com and manually deleted it from the device list (as explained here: http://help.apple.com/icloud/#mmfc0eeddd), and it has not gone back online since (which would cause it to reappear on the device list; Find My iPhone has been turned of in settings on the device; the iClolud account has been deleted from the device; or the entire devices has been erased and restored.
    Unfortunately, there's no other way to track the phone other than through Find My iPhone.  You could call your carrier and see if they would blackliste it so at least the theif couldn't use it.

  • Difference between sub-query and corelated subquery

    Hi,
    can anyone please give me the clear difference between sub-query and coreleated subquery with an example.
    I am very much confused with the both.
    Also please let me know in which cases/situation these are used.
    Thanks,

    Basically Sub Query is Query within Query. There are different type of SubQuery.
    1. Scalar Sub Query
    Query that is totally independent from the main query.
      select empno, (select count(*) from emp) total_emp
        from emphere the subquery is totally independent of the main query.
    2. Corelated Sub Query
    The sub query reffers to the main query.
      select empno, (select deptname from dept d where e.deptno = d.deptno) deptname
         from emp e3. Inline view
    A sub query that is used as a table or view in a SQL
    select *
      from (select empno, deptname
              from emp e, dept d
             where e.deptno = d.deptno)
    where sal > 100

  • Regarding Sender query and receiver query

    Hi Masters
          I have one sender query and receiver query. Both queries contain G/L account.
    First I got sender query report, in this report I drill down one free charactteristics field to get correponding field sales document in receiver report.
    Is it mandatory which field i drill down in sender report should be in receiver report?
    Could you please help ?
    Thanks in Advance
    Raja.S

    I would rewrite the first one to:
    Select t.id_entity,t.id_trade_ref,p.am_stock
    from trade t,posting p
    where t.id_trade_ref = '5V973781B'
    and p.id_trade_ref = t.id_trade_ref
    This way, you really make the join between the table.
    I think the join is better because it uses less code. I do not think you will notice much performance win between one or the other, especially because it concerns only a few rows.

  • Query with subquery should return value but doesn't

    When I run this SQL, it returns no value:
    SELECT vfn.cat
    FROM vps_fishery_ner vfn, valid_fishery vf
    WHERE vfn.plan = vf.plan
    AND vfn.cat = vf.cat
    AND vf.permit_year = 2010
    AND vf.moratorium_fishery = 'T'
    AND vfn.vp_num = 211652
    AND vfn.ap_year = 2010
    AND vfn.plan = 'MUL'
    AND vfn.date_issued = (SELECT MAX(date_issued)
    FROM vps_fishery_ner
    WHERE vp_num = 211652
    AND ap_year = 2010);
    In order to test, I take out the subquery and run it separately:
    SELECT MAX(date_issued)
    FROM vps_fishery_ner
    WHERE vp_num = 211652
    AND ap_year = 2010;
    Returns 02-APR-10
    Then I paste this date into the original query (using the TRUNC function, of course, since I hardcode only the DDMMYY part of the date):
    SELECT vfn.cat
    FROM vps_fishery_ner vfn, valid_fishery vf
    WHERE vfn.plan = vf.plan
    AND vfn.cat = vf.cat
    AND vf.permit_year = 2010
    AND vf.moratorium_fishery = 'T'
    AND vfn.vp_num = 211652
    AND vfn.ap_year = 2010
    AND vfn.plan = 'MUL'
    AND TRUNC(date_issued) = TO_DATE('02-APR-10');
    And this returns the required value, 'A'.
    So why doesn't the full query with subquery work, if the value that is returned by the subquery is valid and works when you just paste it in?
    Thanks.

    Hi,
    Not sure about your question.
    But you say when you uss 01-apr-10 you get the expected results.
    So why dont you try using trunc on botht sides
    SELECT vfn.cat
      FROM vps_fishery_ner vfn, valid_fishery vf
    WHERE vfn.plan = vf.plan
       AND vfn.cat = vf.cat
       AND vf.permit_year = 2010
       AND vf.moratorium_fishery = 'T'
       AND vfn.vp_num = 211652
       AND vfn.ap_year = 2010
       AND vfn.plan = 'MUL'
       AND trunc(vfn.date_issued) = (SELECT MAX(trunc(date_issued))
                                FROM vps_fishery_ner
                               WHERE vp_num = 211652
                                 AND ap_year = 2010);Rememeber if you are couting on some Index to be used you might want to recheck.
    IN answer to your question why it does not return with subquery included, because the TIME PART is not the same.
    You yourself proved it by using the supplying only the date part.
    Regards,
    Bhushan

  • Difference between JOIN and Subquery

    HI all,
    What is the difference between JOIN and Subquery?
    Regards,
    - Sri

    JOIN is combining factor or two data sources.
    Subquery is the resultant set of datasource(s) which can be joined/compared to other data source in your main query.

  • Have some doubt regarding the  weblog (Lookup's in XI made simpler)

    Hi All,
    I have created the same scenario as mentioned in Siva's weblog (Lookup's in XI made simpler).
    I having some doubts regarding the scenario, it will be great if you help me to resolve the same.
    I am having a file-file scenario where I need to do lookup in database(MS-Access)  through mapping.
    The standard file-file scenario is in place and in addition I have created a receiver jdbc channel . I  have also created the receiver agreement for the same in the cofiguration.
    While creating the receiver agreement you have to specify the interface name which includes the message type…I have specified the normal format which we specify while configuring the jdbc receiver adapter.
    In the message mapping I have created a advance user defined function as mentioned in your weblog which calls my receiver jdbc channel.
    I have also specified the select query to be executed in the mapping program.
    While testing I am getting the following error
    Cannot produce target element /ns0:Role_MT/URole. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd
    <b>Can you please suggest me what all I need to do in addition to the file-file scenario for this lookup scenario to work.</b>
    Thanks and Regards
    Rahul

    Hi,
    Following is my user defined function
    //write your code here
    String Query = "";
    Channel channel = null;
    DataBaseAccessor accessor = null;
    DataBaseResult resultSet = null;
    Query = "Select URole from  Lookup where UName = '  " + UName[0] + "  ' and UPassword = '  " + Pwd[0] +" '  ";
    try{
    channel = LookupService.getChannel("DB_service","JDBC_channel_receiver");
    accessor = LookupService.getDataBaseAccessor(channel);
    resultSet  = accessor.execute(Query);
    for(Iterator rows = resultSet.getRows();rows.hasNext();){
    Map rowMap = (Map)rows.next();
    result.addValue((String)rowMap.get("URole"));
    catch(Exception ex){
    result.addValue(ex.getMessage());
    finally{
    try{
    if (accessor!= null) accessor.close();
    catch(Exception ex){
    result.addValue(ex.getMessage());
    Thanks and Regards
    Rahul

  • Regarding query

    Dear Experts,
    I have one doubt regarding below query...
    I have two tables of data like below..
    Table A
    CustId Name CustType
    1 xyz pres
    2 yyy Pres
    3 zzz Pres
    4 RRR pres
    5 kkk Pres
    Table B
    AFfId From_cust_Id To_cust_id Afftype
    11 1 2 Hosp
    12 1 3 Hosp
    13 2 4 Hosp
    14 2 5 Hosp
    I want to generate the output in the below format...
    CustId Inst1 Inst2 Inst3
    1 xyz yyy zzz
    2 yyy RRR KKK
    Please help me on this query..
    Thanks a lot in advance..
    Oracle Version : 10g
    Thank you.
    Sunitha.

    sunitha2010 wrote:
    Dear Experts,
    I have one doubt regarding below query...I don't see any query below
    How to ask question
    SQL and PL/SQL FAQ
    Handle:     sunitha2010
    Status Level:     Newbie
    Registered:     May 13, 2010
    Total Posts:     43
    Total Questions:     17 (15 unresolved)
    why so MANY unanswered questions?

  • Doubt regarding SQL execution

    Hi Friends,
    Am using Oracle 10g DB - 10.2.0.3.0
    I have some basic doubts regarding sql query execution by Oracle.
    Say, Am executing a query from a toad/sqlplus session for the first time, it takes 10 secs then 1 sec and so on.
    Same thing happens for every 15 minutes.(Any specific reason for this ??).
    It takes more time when it executes first because of parsing and all those stuff but from then on it picks from the
    shared pool right??.. How long will it be there in Shared Pool does Oracle maintain any specific time period to clear that query from shared pool memory. How does Oracle handle this.
    Another thing is, say, I have a report query, I run this query monthly. What will be the execution time when I run this query each and every month. Will Oracle parse this query everytime I run. How do I improve the performance in this situation (May sound odd :)).
    Regards,
    Marlon

    Say, Am executing a query from a toad/sqlplus session for the first time, it takes 10 secs then 1 sec and so on.
    Same thing happens for every 15 minutes.(Any specific reason for this ??).
    It takes more time when it executes first because of parsing and all those stuff but from then on it picks from the
    shared pool right??.. How long will it be there in Shared Pool does Oracle maintain any specific time period to clear that query from shared pool memory. How does Oracle handle this. Share Pool caches the SQL statement. So when you execute the same SQL for the second time it goes for a soft parse. But this is not the only reason for the query to execute faster the second time. The time difference between a soft parse and hard parse is very minimal. So it really does not matter unless you are executing the same query several number of times.
    The thing that really matters is the Data Buffer Cache. That is the rows that are selected by your query are cached into the Data buffer that is available in the SGA. So for the next time when you run the same query the IO is reduced as the data is available in the memory and you don't have to go to your disk to get the data.
    But the data in Data Buffer is not persistent, meaning it follows the FIFO rule. That is first in first out. When the Data Buffer is full the content of the buffer is removed in the FIFO order.
    Another thing is, say, I have a report query, I run this query monthly. What will be the execution time when I run this query each and every month. Will Oracle parse this query every time I run. How do I improve the performance in this situation (May sound odd :)). Like the Data Buffer the Shared Pool is also maintained in the FIFO order. So if the query is still in the Shared Pool the query will be soft parsed else it will be hard parsed. But its very rare that you will have a query in your Shared Pool for a month.

  • Help in Ad-hoc query and Hr form editor

    any body have material links of Ad-hoc query(it means how the reports are generated with Ad-hoc query) and Hr form editor(with examples) plz forward it to me???????????

    Hi,
    HR Ad Hoc Query is the special version of InfoSet Query with the HR object selection.
    You can find the system documentation here:
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/f9/cc9138e4a0341fe10000009b38f8cf/frameset.htm
    However I doubt the use of documentation of the query generator. So what is your concrete question?
    Or in any R/3 via application help of transaction SQ01.
    Also HR580 is a good course.
    Regards,
    Michael

  • Creating t.code for ABAP query and Transport  it TO Production and run it .

    Hi Friends
    Thanks for ur reply ,
    The requirement is that i want to create tcode for abap query and that query can be regenearted ,
    in case of regeneration programe name i got answer programame name will be change, i created and modified query but i saw the same programe name ,,, may be it changed when it is trasnported if so then what ??
    and also pls give me solution for asiging tcode for query which is going to be regenerated.
    thanks and regards
    farukh

    Dear Farukh,
    As we know,
    Query is created in Production server and a corresponding program is generated by System.
    What we have to do is just to assign the program to the desired transaction code in Development server and transport it.
    If you have any doubts please let me know.
    Kindly assign points if you find this info usefull.
    Regards,
    Lijo Joseph

  • In operator and subquery

    I have created a sql query for oracle rdbms. I am passing a particular id in the subquery of my main query . I have one major difference in the query whenever i use a subquery with IN operator and using IN_list values in IN operator. I found that whenever after using IN operator with sub-query ,all the tables were going for full tablescan but if i used in_list values in the IN operator , all the required indexes were getting used.
    This is part of the query
    from ems_exception
    left outer join EMS_EXCEPTION_LINK_MAP
    on (ems_exception.ID = EMS_EXCEPTION_LINK_MAP.EXCEPTION_ID
    and ems_exception.id in  (SELECt ID
      FROM (SELECT  inner.*,ROWNUM rn
              FROM (SELECT /*+ UNNEST */ e.id,max(e.created_ts) aa
                        FROM ems_exception e
                        join ems_status_def
                        on ( e.status_id =ems_status_def.id and ems_status_def.id in (1,2,3))
                        join ems_exception_link_map
                       on (e.id = ems_exception_link_map.exception_id)
                       join ems_link
                       on (ems_link.id = ems_exception_link_map.link_id)
                       group by e.id 
                       order by aa desc
                       ) inner) outer
                       where outer.rn>=201 and outer.rn <=400 ))
    If i use values instead of the sub-query , the query plan was optimum . Is combination of IN operator and subquery bad in terms of query performance?

    It's not inherently bad - but it does depend on the optimizer getting  good estimate of the data volume.
    Did you test with 200 distinct values in your IN list, and can you see in the execution plan Oracle estimate of how many rows the subquery would generate.
    Regards
    Jonathan Lewis

Maybe you are looking for

  • Locating a properties file

    Hey, My application makes use of a properties file which it needs for some connection settings. Currently the properties file is in the same directory as the .jar (.exe) so everything works fine. but i at some point id want the .exe to be on the desk

  • How make class w/public var like "length" in array? i.e. final, set at init

    In any array, you get the length of it by calling "MyArray.length". length is a public variable, but it cannot be set. If you try: String[] str = { "ss" }; str.length = 2; you'll get an error saying you can't change a final variable. So my question i

  • How To Get Adobe Flash Movie To Work On Another Computer?

    Somebody please please help me. I use a English language Windows operating system, forgive me. I made an interactive book in Adobe Indesign CS 5. The content, which are all graphics, was all originally created in Adobe Illustrator CS5, but I exported

  • Using TKPROF

    This is my first time using tkprof. I generated a sql trace in USER_DUMP_DEST. Then, I tried to use tkprof to format it but it said: SQL> tkprof SP2-0042: unknown command "tkprof" - rest of line ignored. SQL> So, what is missing?

  • View/Compare Documents does not appear

    How can I get View/Compare Documents to appear in Acrobat X?