INSTR and SUBQUERY

Hello
I have to statements here that I don't understand. Can anyone explain what these two statements do.
In the first statement I don't know what the 3 and 2 is.
INSTR:
SELECT INSTR('CORPORATE FLOOR','OR', 3, 2) "Instring"
FROM DUAL;
SUB-SELECT:
SELECT a.ename, a.sal, a.deptno, b.salavg
FROM emp a, (SELECT deptno, avg(sal) salavg
FROM emp
GROUP BY deptno) b
WHERE a.deptno = b.deptno
AND a.sal > b.salavg;

Hi,
INSTR - gives the starting position of the occurence of the string that is searched for, starting from the given position and if it is of nth occurrence.
INSTR('STRING THAT IS SEARCHED' ,'STRING TO SEARCH',
SEARCH_FROM_POSITION, SEARCH_FOR_Nth_OCCURRENCE)
STRING THAT IS SEARCHED = 'CORPORATE FLOOR'
STRING TO SEARCH = 'OR'
SEARCH_FROM_POSITION = 3 (i.e. from the 3rd char)
SEARCH_FOR_Nth_OCCURRENCE = 2 (i.e. the second time 'OR'
occurrs after the 2nd char)
For the following query would return - 14.
SELECT INSTR('CORPORATE FLOOR','OR', 3, 2) "Instring"
FROM DUAL;
SUBQUERY,
That is not a subquery that you had qiven, it is an inline view. It is nothing but a query in the FROM clause.
Regards,
Bharath

Similar Messages

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

  • PL-SQL Solve: Using INSTR and SUBSTR

    I am trying to work on this and cannot get a solution. Please help
    You have to use INSTR and SUBSTR to solve
    Question:
    You have the following acceptable value
    Numberic: 0-34
    80-100
    or Non Numberic X S U D- D D+
    Im have to use INSTR and SUBSTR functions to test that the value is a valid (as above) number before TO_NUMBER is called:
    SELECT TO_NUMBER('?? ') //HERE ?? and a space (for 100 etc) is for the values as above
    FROM DUAL
    WHERE ....INSTR(......)<=;
    (Hence if the number is true then number comes back or it says no rows)
    and also id non numberic it should also be tested.
    I am completely unsure about it but tried this
    SELECT TO_NUMBER('34 ')
    FROM DUAL
    WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
    AND
    INSTR('0123456789',2,2)<=9
    AND
    INSTR('0123456789',3,3)=0;
    Please help

    We have the following value that we can use:
    Numeric: 0-34 and 80-100 only
    or Non Numberic X S U D- D D+
    Have to use INSTR and SUBSTR functions to test that the value is a valid
    (for now only trying to create a function which can later be put into a procedure.)
    SELECT TO_NUMBER('12 ') //e.g HERE 12 and a space for the values as above
    FROM DUAL
    the where clause looks at all three spaces to make sure values are correct (given number or non-numberic values only)
    (Hence if the number is true then number comes back (meaning true)
    or it says NO rows)
    If value is non numeric, test it to allow non numberic also.
    I am completely unsure about it but tried this
    SELECT TO_NUMBER('34 ')
    FROM DUAL
    WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
    AND
    INSTR('0123456789',2,2)<=9
    AND
    INSTR('0123456789',3,3)=0;
    Something like this has to be done.....subst (instr, x,x,) i think mite help.

  • 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

  • How to combine both values and subquery in the insert statement

    Hi everybody,
    This is a case of inserting rows into a final results table from a temporary one. Actually, one of the fields is not always given in the temporary table. Thus, when inserting the rows into the final results table, an error message comes up to.
    More clarification:
    final results table(F_RESULT): field1, field2, field3 ( they are also primary keys with not null constraint)
    temporary table(TEMP): field2, filed3
    Is it possible to combine both values and subquery branchs of the insert statement:
    Insert into F_RESULT (field2,field3) select field2,field3 from TEMP;
    Insert into F_RESULT (field1) values (0);
    into only one like this:
    Insert into F_RESULT (field1,field2,field3) values (0, select field2 form Temp, select field3 from Temp);
    Or there is another more effective solution. The main problem for me is the message that doesn't accept the null value. From the data integrity point of view, it is accepted to set field1 to zero.
    Any hints?
    Thanks for your reply.

    That's easy, you can select any value from a table:
    Insert into F_RESULT (field1,field2,field3)
    select 0, field2, field3 from Temp;

  • Some instr and substr fundamental

    Hi,
    In a procedure, my input parameter would be 123,345,456,567......I will put this in a loop..
    My requirement is like first it will take 123 and i will do some calculation end loop,
    then 345 and i will do some calculation end loop,
    then 456 and i will do some calculation end loop,
    then 567 and i will do some calculation end loop, and so on...
    i think there is some instr and substr fundamental..
    Will be great if i get some suggestion to solve the issue...
    Thanks,
    HP

    Not quite.
    Dbms_utilty.comma_to_table will do the job quite nicely.
    http://www.java2s.com/Code/Oracle/System-Packages/demonstratestheuseofDBMSUTILITYTABLETOCOMMAandDBMSUTILITYCOMMATOTABLE.htm
    Sybrand Bakker
    Senior Oracle DBA

  • Vendor Evaluation Delivery Subcriteria Shipping Instr and Adher to Conf Date

    Hi experts,
    I have Vendor Evaluation configured for Delivery subcriteria Shipping Instr and Adher to Conf Date.  These are set to scoring method 6 and B respectively.  In the Purchasing Org Data, for subcriteria Delivery, I have equal weighting set for all 4 subcriteria (on-time del, quantity reliability, shipping instr, and adher to conf date).  When I run the vendor evaluation in ME61, and look at the evaluation of subcriteria, I see a score and weight for on-time delivery, and quantity reliablity.  But for shipping instructions and adher to Conf Date, there is no score and the weight is 0.0.  Does anyone know why there is no weight shown?  I know I have to maintain the scores for shipping instr and adher to conf date but I should see weight as 25% since I set these 4 subcriteria to equal weighting.  Can anyone help?  Thanks!
    Regards,
    Julie

    Hi,
    As an example its not available, nor tried self. As a common rule - if a main criteria created and sub criteria exists, when you run evaluation for main - excluding a stage of sub is not possible.
    Secondly try transaction code: ME6C
    Help says: Set this indicator if you only want to display those vendors that do not have
    an evaluation for certain main criteria. When you click on Execute, a screen allowing you to choose one or more main criteria appears. The missing evaluations for these criteria are then listed.
    here you can selection option to include/exclude evaluation.

  • INSTR and INSTRB difference

    Hi all
    can anybody show me the difference between INSTR and INSTRB
    and LENGTH and LENGTHB functions??
    And I can't understand LTRIM function briefly.
    Thanks....

    My NLS settings is below. I select these data from v$nls_parameters
    NLS_LANGUAGE      AMERICAN
    NLS_TERRITORY      AMERICA
    NLS_CURRENCY      $
    NLS_ISO_CURRENCY      AMERICA
    NLS_NUMERIC_CHARACTERS      .,
    NLS_CALENDAR      GREGORIAN
    NLS_DATE_FORMAT      DD-Mon-RRRR
    NLS_DATE_LANGUAGE      AMERICAN
    NLS_CHARACTERSET      WE8ISO8859P1
    NLS_SORT      BINARY
    NLS_TIME_FORMAT      HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT      DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT      HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT      DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY      $
    NLS_NCHAR_CHARACTERSET      AL16UTF16
    NLS_COMP      BINARY
    NLS_LENGTH_SEMANTICS      BYTE
    NLS_NCHAR_CONV_EXCP      FALSE
    I understand the first, but I didn't understand the second. Why the result was 27
    Thanks...

  • Functional difference between VISA resource name ASRL1::INSTR and COM1

    Config: LabVIEW 6.02, VISA 2.6.0
    I have used a text constant for "VISA Configure Serial Port.vi" for years, and just now I have run into problems.
    With my application, a text constant of ASRL2::INSTR would properly open the port, but it would not send any data, but using COM2 worked.
    What is the difference?

    MAX sets up serial port aliases automatically when possible. Let me try to explain.
    If the alias "COMx" was not previously configured in NI-VISA, and you have a serial port really named "COMx", and that VISA resource string does not have any other user-configured alias, then MAX will bind that alias to that port, regardless of what the full VISA resource string is. That part actually makes sense and shouldn't confuse anyone. If the alias "COMx" is taken, or the user has manually configured a different alias for the serial port (such as "MyDMM", for example), then MAX does not auto-assign the alias for that port. So far so good.
    The confusing part in many cases is how NI-VISA itself assigns the VISA resource string. For COM3, normall
    y NI-VISA would assign ASRL3::INSTR, and so on. There is 1 conflict that usually screws everything up. Since NI-VISA on Win32 allows you to open the parallel port by default as ASRL10::INSTR (for extremely historical reasons), the conflict occurs when you really have a COM10. It's not a terrible conflict, but it is confusing. NI-VISA will match every other port that it possibly can, and then just assign a unique resource name (ASRLx::INSTR) for COM10.
    I am not sure why in your case NI-VISA didn't match COM3 to ASRL3::INSTR. If you want to do some experimenting, try this. Go into MAX, delete all your VISA aliases, delete LPT1 from the tree, exit MAX, restart MAX, and refresh. See if that cleared it up.
    Dan Mondrik
    Senior Software Engineer, NI-VISA
    National Instruments

  • Select list and subquery: "LOV query is invalid"

    Hi all,
    I want to create a select list with the following format:
    "name1 (count of another table)"
    "name2 (count of another table)"
    I've boiled it down to a simple query with a non-correlated subquery that works fine in SQL*Plus but not as an LOV:
    select table1.field1 || (select count(*) from table2) d,
    table1.field2 r
    from table1
    I get this (Apex 3.2.1):
    1 error has occurred
    * LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.
    Even this doesn't work:
    select table1.field1 || (select 'a' from dual) d,
    table1.field2 r
    from table1
    I've tried it with an inline view, joining table1 to a select from table2 that returns the count, but I get the same result. Any ideas?
    Edited by: MalcA on Jan 22, 2010 12:14 PM

    I don't know, but the difference is that the count(*) code goes from the select clause to the from clause.
    Other times I had the same problem and always did it and it was the solution.

  • IIF with InStr and LEFT -1 Causes #Error in SSRS 2008R2

    Hello,
    I'm using IIF with InStr to test for a "/" in a field on a report.  The left function works fine unless I try to subtract 1 from it.  This code works fine:
    =IIF(InStr(Fields!WellCompName.Value,"/")=0, Fields!WellCompName.Value, left(Fields!WellCompName.Value,InStr(Fields!WellCompName.Value,"/")))
    But this code causes the True condition to yield #Error in the report when I add the -1 to the end of the left function:
    =IIF(InStr(Fields!WellCompName.Value,"/")=0, Fields!WellCompName.Value, left(Fields!WellCompName.Value,InStr(Fields!WellCompName.Value,"/")-1))
    I do need -1 to remove the "/" but it doesn't work with IFF and LEFT.
    Thanks

    Hi SomeDBGuyOutThere,
    I have tested on my local environment and can reproduce the issue, your issue caused by when the value in the field WellCompName don't contains "/". the function "left(Fields!WellCompName.Value,InStr(Fields!WellCompName.Value,"/")-1)"
    in the expression is invalid and will caused the error.
    In your scenario, please modify the second expression as below to avoid the error when there is no "/" in the string:
    =IIF(InStr(Fields!WellCompName.Value ,"/")=0,
    Fields!WellCompName.Value,
    left(Fields!WellCompName.Value,InStr(IIF(InStr(Fields!WellCompName.Value,"/")=0,"Test1/Test2",Fields!WellCompName.Value),"/")-1))
    Note: when WellCompName don't include "/" we given an test string "Test1/Test2" in the expression to avoid the error.
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • Instr. and DAQ Assistants - Time to take off the training wheels?

    Hi everyone,
    I have written a control system program using a producer/consumer with state machine architecture - textbook LabVIEW beginner intermediate.
    In the producer, I have 6 different DAQ assistants taking AI and DI data from PXI mounted data acquisiton cards and two Instr. Assistants taking data from PXI serial ports.  In the consumer, I have a similar situation.  There are 7 DAQ assistants sending digital and analog requests to 3 different PXI chassis and one Instr. asssistant sending requests to a PXI serial port. 
    Is this frowned upon?  Would any of you pros call this a finished job if it is still bound with Assistants?  I have looked at the code involved in making these assistants into LabVIEW code (writing them out, so to speak), but it is complex and I haven't been able to put in the time to learn all of the different DAQmx and VISA functions and subVI's. 
    However, I have some difficulties that arise when, for instance, a component that is monitored/written to by a serial port is turned to manual control and the assistant times out.  It times out the entire control system, which is not desirable.  Is the fix in error handling, or getting rid of the assistants altogether?
    Any responses are appreciated - even if you are the bearer of bad news!
    Brad

    Hi Brad,
    Using DAQ assistants in a loop does come with some overhead. However if you are acquiring at relatively low speeds and do not want to use the DAQmx VIs, it shouldn't be a problem. Though programming using DAQmx VIs might look somewhat intimidating it follows a general priciple common to most I/O in LabVIEW. You open/create a channel, configure it, read or write and then close it. Generally, only the read or write VIs will be in the loop. So doing the creation and configuration every iteration of the loop is the overhead.
    I am not entirely sure what is timing out and what you are doing to cause a time out. There are two ways to generally fix time out errors. One, as you pointed out, is to handle the error. You can do this by unbundling the cluster to look at the error code, if it is a time out error, you can reset the error cluster.
    The other solution is to increase the timeout for the DAQ assistant. (Wire the time (in seconds) you want it to wait, to the timeout input of the DAQ Assistant).
    Cheers
    Malay Duggar
    NI

  • Oracle Alert and subquery

    I am using sub query in oracle alert it is not working fine any person guide me

    select distinct
    employee_number,
    full_name,
    c.proposed_salary decode(substr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),instr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),'.')1,9),'Allowance',c.proposed_salary*25/100,'None%',0,0)+
    decode(substr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),instr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),'.',1,2)+1,4),'Allo',c.proposed_salary*15/100,'None',0,0) +
    decode(substr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),instr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),'.',1,4)+1,4),'None',0,200) as net
    INTO
    &EMPNO,
    &EMPNAME,
    &NET
    from per_all_people_f a , Per_all_assignments_f b,PER_PAY_PROPOSALS_v c
    where a.person_id = b.person_id
    and b.assignment_id = c.assignment_id
    AND c.element_name = 'Basic Salary'
    and c.pay_proposal_id = (select max(pay_proposal_id) from PER_PAY_PROPOSALS_v where ASSIGNMENT_ID =b.assignment_id
    and element_name = 'Basic Salary'
    and approved = 'Y')
    and
    DECODE (b.assignment_type,
    'E', hr_general.decode_lookup ('EMP_CAT', b.employment_category),
    'C', hr_general.decode_lookup ('CWK_ASG_CATEGORY',
    b.employment_category
    )='Labor'
    and TRUNC(sysdate) between a.effective_start_date and a.effective_end_date
    AND TRUNC(sysdate) between b.effective_start_date and b.effective_end_date
    and c.proposed_salary decode(substr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),instr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),'.')1,9),'Allowance',c.proposed_salary*25/100,'None%',0,0)+
    decode(substr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),instr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),'.',1,2)+1,4),'Allo',c.proposed_salary*15/100,'None',0,0) +
    decode(substr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),instr(HR_GENERAL.DECODE_PEOPLE_GROUP(b.people_group_id),'.',1,4)+1,4),'None',0,200) >= 3000

  • Update with exists and subquery

    Hi how to pass index to this sql
    Table pap ( eqid,seq,histseq,docno,status,value1,value2)
    PK(eqid,seq,histseq) and indx (docno)
    table pa ( eqid,seq,docno,status,value1,value2)
    PK(eqid,seq) and indx (docno)
    update pa
    set (value1,value2) = (select pap.value1,pap.value2 from pap
    where pap.eqid = pa.eqid
    and pap.seq = pa.seq
    and pap.histseq =1
    and pap.docno <> pa.docno
    and pap.status = 4 )
    where pa.status=1
    and exists ( select 1 from pap
    where pap.eqid = pa.eqid
    and pap.seq = pa.seq
    and pap.histseq =1
    and pap.docno <> pa.docno
    and pap.status =4 )
    It is doing fulltable scan on pa and using hash join .
    How to write update with subquery method also ?

    There's nothing wrong with a full scan.
    Please read this explanation/example: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9422487749968
    If you want more explanation then please follow these guidelines below, so we have sufficient inputs:
    [When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
    [How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    Remember to put the tag befor and after the examples you post.
    See http://forums.oracle.com/forums/help.jspa regarding tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • INSTR and bind values

    Hi everybody,
    I would like to search for a certain string in a varchar2 type column using the INSTR function.
    Is it possible to use bind variables this way ?
    bind2 varchar2(50) := 'mysearch';
    if instr(bind1, bind2 ) <> 0 then
    I also tried to use regexp_instr or regexp_like but it still does not find my bind2 string in the bind1 variable.
    Thank you for your help
    Jean-michel, Nemours, France

    Hi, Jean-Michel,
    Are you sure the problem has anything to do with how you're using INSTR? Maybe you're not using the values you think you're using. Display them right before calling INSTR, like this:
    dbms_output.put_line (      vcurlignesawr.output
                   || ' = vcurlignesawr.output, '
                   ||     trouve
                   || ' = trouve before calling INSTR'
    if instr(vcurlignesawr.output,trouve) != 0 then
    user11986785 wrote:Here is the sql I am using :
    +...cursor lignesawr(baseid in NUMBER,snap_debut in NUMBER,snap_fin in NUMBER) is+
    SELECT output, rownum r FROM table(DBMS_WORKLOAD_REPOSITORY.awr_report_text (baseid, 1, snap_debut,snap_fin));
    TYPE Lignes IS TABLE OF VARCHAR2(50);
    TYPE TabLignes IS TABLE OF Lignes INDEX BY binary_integer;
    recherches TabLignes;
    +...+
    for vcurlignesawr in lignesawr(baseid,snap_debut,snap_fin) loop
    What values do you want to use inside the cursor? You defined the cursor with 3 parameters (baseid, snap_debut and snap_fin). Those names are only used inside the cursor definition; they have nothing to do with any variables anywhere else, including the code that opens the cursor. If you open the cursor like this:
    for vcurlignesawr in lignesawr(x, 5, x+5) loopthen, when it runs, it will do this
    SELECT  output
    ,      rownum     r
    FROM      table ( DBMS_WORKLOAD_REPOSITORY.awr_report_text ( x       -- the parameter baseid
                                              , 1
                                        , 5       -- the parameter snap_debut
                                        , x + 5  -- the parameter snap_fin
               );You have to pass values to the cursor. You can have local variables that have the same names (baseid, snap_debut and snap_fin), but I don't recommend it, because they would be completely separate variables, and people reading the code would get confused about which variable was meant at any time.
    ... Sorry for the bad display.
    How is it possible to display the code properly ?Whenever you post formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    This site normally doesn't display the &lt;&gt; inequality operator.  Use the other, equivalent inequality operator, !=, when posting here.  For example:if instr (vcurlignesawr.output, trouve) != 0 then

Maybe you are looking for

  • My Ipod Touch Won't Show as a device in iTunes

    Hope you can help, I'm running all the latest software (ie 10.5.6) on my iMac 2.GHz Intel Core 2 Duo. When I connect my iPod Touch, iPhoto automatically opens and the device is shown but my iTunes remains un-opened. When I manually open it and re-try

  • Error message: The iTunes update server could not be contacted...

    Windows PC, no issue with internet connection. Had issue for 3 days out of blue. Can access iTunes store itself. Run various tests/changes (hosts/proxies/protection software) suggested on support pages, with no result. Any help welcomed. Diagnostics

  • Windows 7 DNS and Group Policy Issues

    Hi, We have several suites of Windows 7 domain connected PC's. In one of the suites I have been called into look at 3 different PC's where the users have not got mapped drives, desktop backgrounds, internet connectivity - because their group policies

  • Vendor Evaluation in srm 4.0

    Hi Experts, I have 2 questions: 1. Does anyone have any documentation about Vendor Evaluation in SRM 4.0 that can send me   ? 2. I build new questionnaire in SRM 4.0. When I created G/R in the SRM system I got error  message "Inconsistent situation i

  • Hotmail won't take my HTML Email

    Hello All! Hotmail doesn't seem like it wants to receive my html email. I built the "newsletter" and put it with it's graphics onto my website. Then I pushed "command + i" and it puts it into my Mail appl. like an html email. All seems well.... Then