SQL Code Analyzer

Hi all

My requirement is analysis a query and find out what are the tables and the columns involved.

We have columns Source and the only table names in a query.

Query can be any format as sub, with clause query...

There are 1000's of queries that analysis must...

Is there a simple way... ???

Thank you

Elayaperumal S

Yes.

The following approach can be used (does any syntax, but does the basics):

SQL> create or replace function XmlParse( dynamicSQL varchar2 ) return XmlType is
  2          c       clob;
  3          xml     XmlType;
  4  begin
  5          dbms_lob.CreateTemporary( c, true );
  6          sys.utl_xml.ParseQuery(
  7                  user,
  8                  dynamicSQL,
  9                  c
 10          );
 11
 12          xml := new XmlType(c);
 13          dbms_lob.FreeTemporary(c);
 14          return( xml );
 15  end;
 16  /

SQL>
SQL> with xml_parse( xml ) as(
  2          select XmlParse( 'select sysdate as day, e.*, d.* from emp e, dept d where e.deptno = d.deptno and empno = :1' ) from dual
  3  )
  4  select
  5          t.*
  6  from       xml_parse p,
  7          XmlTable( '/QUERY/SELECT/SELECT_LIST/SELECT_LIST_ITEM/COLUMN_REF'
  8                  passing p.xml
  9                  columns
 10                          table_name varchar2(30) path 'TABLE',
 11                          column_name varchar2(30) path 'COLUMN'
 12          ) t
 13  /

TABLE_NAME                     COLUMN_NAME
------------------------------ ------------------------------
EMP                            EMPNO
EMP                            ENAME
EMP                            JOB
EMP                            MGR
EMP                            HIREDATE
EMP                            SAL
EMP                            COMM
EMP                            DEPTNO
DEPT                           DEPTNO
DEPT                           DNAME
DEPT                           LOC

11 rows selected.

SQL>

Tags: Database

Similar Questions

  • Result passage of PL/SQL code for the page element

    Hello

    I have created a process in after the header to fill data to the page of the form elements.  The pl/sql code is like bellows.  Then I got the error message:

    ORA-06502: PL/SQL: digital or value error: character number conversion

    My question is that I do not see the difference in format between the page element and block pl/sql variables (e.g. : P31_STUDY_ID vs v_P31_STUDY_ID), they are either numeric or text field (in fact I have hidden field, but don't see conversion back to the digital field solved the problem).  And don't see needs to set the format mask.  Is there another way to detect the column that causes the problem, or if there is a syntax error with my assignment (from the variable element on the page)?  Thank you very much!

    ============================

    Declare

    number of v_P31_STUDY_ID;

    number of v_P31_STUDY_SITE_ID;

    v_P31_STUDY_SITE_NAME VARCHAR2 (255);

    v_P31_STUDY_SITE_NUM varchar2 (10);

    number of v_P31_STUDY_SITE_NAME_NUM_ID;

    number of v_P31_STUDY_SITE_OPEN_STATUS;

    v_p31_comments VARCHAR2 (255);

    Start

    Select

    tbl_study_site.study_id,

    tbl_study_site.study_site_id,

    study_site_name,

    study_site_num,

    STUDY_SITE_NAME_NUM_ID,

    STUDY_SITE_OPEN_STATUS,

    Comments

    in

    v_P31_STUDY_ID,

    v_P31_STUDY_SITE_ID,

    v_P31_STUDY_SITE_NAME,

    v_P31_STUDY_SITE_NUM,

    v_P31_STUDY_SITE_NAME_NUM_ID,

    v_P31_STUDY_SITE_OPEN_STATUS,

    v_p31_comments

    of tbl_study_site, tbl_study_site_attrib

    where tbl_study_site.study_id =: p30_study_name

    and tbl_study_site.study_site_id = tbl_study_site_attrib. STUDY_SITE_ID

    and tbl_study_site_attrib. STUDY_SITE_ATTRIB_ID =: P31_STUDY_SITE_ATTRIB_ID;

    : P31_STUDY_ID: = v_P31_STUDY_ID;

    : P31_STUDY_SITE_ID: = v_P31_STUDY_SITE_ID;

    : P31_STUDY_SITE_NAME: = v_P31_STUDY_SITE_NAME;

    : P31_STUDY_SITE_NUM: = v_P31_STUDY_SITE_NUM;

    : P31_STUDY_SITE_NAME_NUM_ID: = v_P31_STUDY_SITE_NAME_NUM_ID;

    : P31_STUDY_SITE_OPEN_STATUS: = v_P31_STUDY_SITE_OPEN_STATUS;

    : P31_COMMENTS: = v_p31_comments;

    end;

    =============================

    Identify the root cause. He's always on the format of the column, there is an error.  Thanks for your help.

  • Apex - disable the button using PL/SQL code

    Hi all

    I use a PL/SQL code to get a DB value, depending on the value that I need to disable the buttons on the Page.

    I tried code below

    IF : P2_FLAG == ' not THEN

    HTP.script ("document.getElementById ("SUBMIT") .disabled = false;", "Javascript");

    END IF;

    It is said screw the page saying - the/apex/f requested URL was not found on this server

    I use Apex 5.0, please need your contributions.

    Hello

    However, if you want to show/hide the button, you can use conditions:

    Open the properties of the button and put Conditions such as "Item = value '.

    Point - P2_FLAG

    Value - N

    To turn on or off, you must run ajax with jquery to get the DB value before charge and then print button.

    It may be useful

    Sunil Bhatia

  • Extensions: Convert T - SQL code

    Hello

    Do we not have an extension for SQL Developer that converts the Oracle in T - SQL code?

    Thank you

    Do we not have an extension for SQL Developer that converts the Oracle in T - SQL code?

    There is such an extension. It is called a "consultant."

    See you soon,.

    Brian

  • Impact of writing more comments in the pl/sql code

    What is the impact of writing more comments in the pl/sql code. If it has an impact on the compile time, it is fine but it has no effect on the runtime? even in nano seconds?

    Hello

    2981581 wrote:

    What is the impact of writing more comments in the pl/sql code. If it has an impact on the compile time, it is fine but it has no effect on the runtime? even in nano seconds?

    Outside advice, comments have no effect on the runtime.

    They can have a big impact on maintenance time.

  • PL/SQL code to add to the data file

    Can someone help me with a PL/SQL code. I want to do the following:

    get the latest data from the tablespace file
    If (value > 30 GB)
    then

    Loop
    change the database add datafile '+ DATA01' size 30 GB
    # Note data file cannot be larger than 30 GB
    # IE if 40 GB is entered as 2 entries are created one for 30 GB
    # the second for 10 GB
    end loop
    on the other
    same logic adds size datafile up to 30 GB
    Loop
    If you go over 30 GB that to create the new data file
    End of loop
    If

    Please excuse the syntax I know its not correct.  In summary,.
    what I want to do is to create data no larger than 30 GB files for the
    extra space simply create new datafiles Nigerian, we reached the "value in".
    limit

    He can be hard-code "«+ DATA01»»

    Note, I don't want to use datafile autoextend I want to control the size of my storage space...

    Any code would be greatly apprecuated.

    Thanks to all those who responded

    create or replace
    procedure add_datafile(
      p_tablespace varchar2,
      p_size_in_gibabytes number
    ) is
      space_required  number := 0;
      space_created   number := 0;
      file_max_size   number := 30;
      last_file_size  number := 0;
    begin
      for ts in (
        select
          tablespace_name,
          round(sum(bytes / 1024 / 1024 / 1024)) current_gigabytes
        from dba_data_files
        where tablespace_name = upper(p_tablespace)
        group by tablespace_name
      ) loop
        dbms_output.put_line('-- current size of ' || ts.tablespace_name || ' is ' ||  ts.current_gigabytes  || 'G');
        space_required := p_size_in_gibabytes - ts.current_gigabytes;
        dbms_output.put_line('-- adding files ' || space_required || 'G up to ' || p_size_in_gibabytes || 'G with files max ' || file_max_size || 'G');
        last_file_size := mod(space_required, file_max_size);
        while space_created < (space_required - last_file_size)
        loop
          dbms_output.put_line('alter tablespace ' || ts.tablespace_name || q'" add datafile '+DATA01' size "' || file_max_size || 'G;');
          space_created := space_created + file_max_size;
        end loop;
        if space_created < space_required then
          dbms_output.put_line('alter tablespace ' || ts.tablespace_name || q'" add datafile '+DATA01' size "' || last_file_size || 'G;');
        end if;
      end loop;
    end;
    /  
    
    set serveroutput on size unlimited
    exec add_datafile('sysaux', 65);  
    
    PROCEDURE ADD_DATAFILE compiled
    anonymous block completed
    -- current size of SYSAUX is 1G
    -- adding files 64G up to 65G with files max 30G
    alter tablespace SYSAUX add datafile '+DATA01' size 30G;
    alter tablespace SYSAUX add datafile '+DATA01' size 30G;
    alter tablespace SYSAUX add datafile '+DATA01' size 4G;
    
  • Dynamic Action run PL/SQL Code runs is not after 4.2.5 upgrade

    APEX 4.2.4 to 4.2.5 11.2 database upgrade

    I have a button to click on DA who owns shares run of PL/SQL Code and update point who worked in version 4.2.4 which is no longer running after the 4.2.5 patch.

    The PL/SQL procedure has been tested autonomous and it runs correctly.

    I tested him DA is actually shot on the click event by adding an alert "DA xxxx pulled" action before the execution of work of PL/SQL action and action alert.

    There is also a similar on DA click which makes the action opposite to the DA problem and it works both are configured in the same way:

    Static DA, run Code PL/SQL - check waiting for result, and not repress with the same Submit and return items.

    Any ideas on a possible cause/solution much appreciated

    Fixed it, the question was the Page elements of return of goods on the action of PL/SQL Code:

    If the target element was empty the action failed, by adding a value in the database through a normal SQL insert then the insert DA completed successfully.

    Removing Page elements at the point of return of the action of PL/SQL and together action update the target element after the DA fires in all scenarios.

    But thanks for the lead

  • How to invoke the export and import of orders for all tables of pl/sql code?

    I want to export a few (not entire schema) tables from one database to another. But I want to run as a PL/SQL package so that I can call it from an application server. So my question is...

    How to call a tax / export commands from pl/sql code (SP or packaging) so that I can call these (SP or packaging) as a JDBC application server call?

    Krishna_Architect wrote:

    I want to export a few (not entire schema) tables from one database to another. But I want to run as a PL/SQL package so that I can call it from an application server. So my question is...

    How to call a tax / export commands from pl/sql code (SP or packaging) so that I can call these (SP or packaging) as a JDBC application server call?

    When all else fails, read the Fine

    The API data pump

  • Need help with a PL/SQL code

    Hello

    I am trying to execute the following PL/SQL code, which translates errors, obviously I'm not doing things, but it gives you an idea what I'm trying to do:

    DECLARE

    INT var_count;

    SELECT COUNT (*) IN var_count

    FROM sys.all_tables WHERE OWNER = 'SAKILA' AND table_name = "ACTOR";

    If var_count > 0 then

    BEGIN

    DROP TABLE "ACTOR";

    END;

    /

    Erros:

    SELECT COUNT (*) IN var_count

    *

    ERROR at line 3:

    ORA-06550: line 3, column 1:

    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

    Start function < an ID > pragma procedure subtype type

    < between double quote delimited identifiers > delete the current cursor

    There is before

    The symbol 'start' has been substituted for "SELECT" to continue.

    ORA-06550: line 7, column 1:

    PLS-00103: encountered the symbol "DROP" when expecting one of the following conditions:

    (begin case declare exit for goto if loop mod null pragma

    raise return select update while < ID >

    < between double quote delimited identifiers of > < a variable binding > < <

    continue the narrow current delete fetch locking insert open rollback

    savepoint sql set run commit forall fusion pipe purge

    Your help to create it in a right way will be appreciated.

    Thank you very much.

    Tonya.

    Try the following:

    My = $ora $csr-> prepare (q {}

    DECLARE

    INT var_count;

    BEGIN

    SELECT COUNT (*) IN var_count

    FROM sys.all_tables WHERE OWNER = 'SAKILA' AND table_name =: ts;

    If var_count > 0 then

    RUN IMMEDIATELY 'DROP TABLE' |: ts | "CASCADE CONSTRAINTS;

    end if;

    END;

    });

  • Wrap the PL/SQL code

    First of all, Hi everyone.

    I need to encrypt my PL/SQL code at run time. I thought using the wrap.exe, but it won't be a good option, once maybe I need to change something in the code and I'll not can send the code wrapped to the final customer. So, I'll use the DBMS_DDL. WRAP, but I have a doubt, I understand that my object will be encrypted in the database, but how can I prevent software this capture SQL (like SQL STATEMENTS TRACE) get the source when creating the object?


    Thank you very much.

    Agree with SomeoneElse, having a license legally correct contract protects your code.

    The package code is not a bad thing if that's what you are providing to the customer and that you have in place adequate source code controls, so you do not lose the source for yourself.  Although there are "unwrappers" out there, it may depend on the version of Oracle as to how well they work, and if they can achieve.  There are tools out there too which can obscure the PL/SQL code by doing things such as the conversion of all the variable names to things without meaning as a0001, a0002, a0003,... and deletes all comments etc before you wrap, so even if someone manages to undo what they are presented with the code that is more difficult to follow.

    Regarding the customer can see SQL running, you won't really be able to do something that, if the customer has access of type DBA to the database; the only thing you can do to avoid this is to provide a managed service where your company has total control of provides a full support for the server, database and applications and the client does not have access to all but the front end of the application.  Of course, if the customer has access to the database and can see running SQL code, then who can actually be beneficial if they have problems, because they can do their own initial analysis to determine the cause and determine if they should send the question to yourselves.

  • What is missing with Pl SQL code?

    Hey guys,.

    I'm learning to get out of this book and the guy has that little bit of Pl/sql...

    It runs organist.

    create table zed (z varchar2 (30);)

    declare the procedure thisway1

    (p_data in varchar2)

    is

    Start

    immediate execution

    "insert into zed (z) values(:z) '.

    using p_data; end thisway1;

    The code is correct?

    Hello

    XevBellringer wrote:

    Hey guys,.

    I'm learning to get out of this book and the guy has that little bit of Pl/sql...

    It runs organist.

    create table zed (z varchar2 (30);)

    declare the procedure thisway1

    (p_data in varchar2)

    is

    Start

    immediate execution

    "insert into zed (z) values(:z) '.

    using p_data; end thisway1;

    The code is correct?

    No code is absolutely correct.  The code may be correct for a specific purpose, which means that it will be incorrect for other purposes.  If this code was copied from a book, the book probably explains the context and why the author chose to use EXECUTE IMMEDIATE when it is not needed.  (You must use dynamic SQL, such as EXECUTE IMMEDIATE, only when you really need to.  This is one of the most important things to know about dynamic SQL statements.  Perhaps the book uses this code to make this point.)

    In itself, the PL/SQL code you have posted will get a compilation error.  The DECLARE statement must have matching BEGIN and END statements.  (The BEGIN and END statements above are for the thisway1 procedure, which is nested in the DECLARE section).  I suspect that you copied only part of the book pulled code.

    The CREATE TABLE statement includes a mistake; "He has 2 left ' (of, but only 1 right ' ')'.  You must have an equal number of each...

  • frmcmp cannot compile the modules containing SQL code that connected to the database

    Hello

    I checked several hundred messages of the forum on the net without finding a solution.

    I have a Linux server with 11.1 WebLogics (11 GR 1 material) and FormsRuntime installed.

    I am logged in as root.

    I put all the environment variables based on the values in default.env.

    In addition, I updated TERM and ORACLE_TERM vt220. And TNS_ADMIN to the location of the sqlnet.ora and tnsnames.ora.

    I compiled a simple .pll containing only the following code:

    IS test PROCEDURE

    an INTEGER: = 0;

    BEGIN

    a: = 1;

    END;

    command:

    frmcmp_batch module = TESTLIBPLAIN.pll userid=myuser/mypassword@mydb module_type = LIBRARY output_file = TESTLIBPLAIN.plx compile_all = Yes = Yes = No. batch connection

    result: successful compilation. generated .plx.

    now, I'm trying to compile an another .pll containing just the following code:

    IS test PROCEDURE

    an INTEGER: = 0;

    BEGIN

    Select 1 in the doubles.

    END;

    command:

    frmcmp_batch module = TESTLIBSQL.pll userid=myuser/mypassword@mydb module_type = LIBRARY output_file = TESTLIBSQL.plx compile_all = Yes = Yes = No. batch connection

    result: error:

    "

    11 forms (form of the compiler) Version 11.1.1.3.0 (Production)

    Copyright (c) 1982, 2010, Oracle and/or its affiliates.  All rights reserved.

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

    With partitioning, OLAP and Data Mining options

    PL/SQL Version 11.1.0.7.0 (Production)

    Oracle V11.1.1.3.0 - Production procedure generator

    Oracle virtual graphics system Version 11.1.1.3.0 (Production)

    Oracle Multimedia Version 11.1.1.3.0 (Production)

    Oracle tools integration Version 11.1.1.2.0 (Production)

    Common tools Oracle area Version 11.1.1.3.0

    Oracle CORE Production 11.1.0.7.0

    Compile the library TESTLIB.

    Invalidate the body TEST procedure...

    Compilation of body TEST procedure...

    ERROR on line 5, column 1 0

    Ignored SQL statement

    Library TESTLIB closing...

    Errors on TEST:

    PL/SQL ERROR on line 5, column 1 0

    Ignored SQL statement

    Could not generate the library.

    FRM-30312: unable to compile the library.

    "

    the two libraries differ by having used SQl commands or not.

    I tried to compile some more complex .pll and .fmb containg the SQL code. I get similar error messages. The messages that I receive for each module are the same, I would get when compiling the module with FormBuilder 9i (Windows) without being connected to the database.

    So my first thought was, this frmcmp_batch is unable to connect to the database.

    BUT:

    From frmcmp_batch with an invalid user, password, or database name not existing (resp. not in tnsnames.ora), results in appropriate error messages (not found TNS, refusal to sign etc.).

    With myuser/mypassword@mydb I don' t get this kind of messages.

    sqlplus myuser/mypassword@mydb works.

    myuser can access all objects in the database mydb.

    mydb tnsping works.

    When I check v$ session on mydb while (!) frmcmp_batch is running, I see that it is in fact a db session, created from myuser: DB-User = myuser, terminal = myappsever, osuser = root, remote process = frmcmp_batch.  And State of the current session of the db is ACTIVE.

    As a result, frmcmp_batch fails with error messages that I expect that when there is no connection to the base, if it is connected!

    Any ideas what could be wrong with my setup?

    Help appreciated.

    Jean

    I found the solution. Seems, fmrcmp 11g can connect to, but compiles not on the 9i database. With the help of a Database 11 g resolves the problem :-)

  • want to understand the stages of executing pl/sql code

    Hello all;

    I want to know the logic of programming for the pl/sql code, what I have written;

    because I was late yesterday to resolve the simple error.

    > > It's link https://forums.Oracle.com/thread/2565867

    OK now that I have written my code same lineup, but few changes:

    now it's working.  as I said above, I want to know the programming logic "flow of execution steps" of pl/sql code

    1 DECLARE

    2 a number: = 10;

    3 number of b: = 20;

    Number 4 c;

    5 procedure findmin (x IN number, are there in numbers, number of Z OUT) IS

    6 BEGIN

    7 < < BLOCK1 > >

    8 x if you can

    9 z: = x;

    10 other

    11 z: = y;

    12 end if;

    13 END;

    BEGIN 14

    15 < < BLOCK2 > >

    16 findmin(a, b, c);

    17 DBMS_OUTPUT. Put_line (c);

    18 * END;

    19.

    10

    PL/SQL procedure successfully completed.

    > > Is this process flow?  > >

    1. the declaration part.

    2 during playback findmin online no 5 then control passes to the line not 16.

    3. after receving input values, control passes back to 5

    4. then compiler executes the code accordingly.

    Question: how many compiler Oracle will execute code written?

    8f953842-815B-4D8C-833d-f2a3dd51e602 wrote:

    1. the declaration part.

    2 during playback findmin online no 5 then control passes to the line not 16.

    3. after receving input values, control passes back to 5

    4. then compiler executes the code accordingly.

    Question: how many compiler Oracle will execute code written?

    1. any declaration section is processed in order to declare and allocate the space/memory etc.  Including declaring the procedure in scope in memory (the procedure is not executed)

    2 execution block to get the code begins with the first statement after BEGIN

    3. the procedure is called in memory with the parameters passed to it.

    4. when the procedure completes execution returns to the statement in the main execution block, after the procedure call.

    Note:

    The compiler is not executing code, it compiles just in memory or stored in the database (depending on whether it is an anonymous block or the stored procedure / package etc..)

    The code isn't really jump 'line by line', because at the time when it is run, it is compiled down to a pcode (or native code if this is allowed), and which may contain several intermediate statements to run the underlying process.  The compiled code however keep track of line numbers of source code of error for the purposes of statement internally.

  • Examples of pl/sql code that can be used in training for new developers

    Hello

    I'm working on a training ride on the pl/sql to some developers who are totally new to PL/SQL. Although they are experienced in another language. I have power point on pl/sql presentations, but they especially the theory oriented with just a few examples. I'm looking for more help to have a few example pl/sql that can be given to interns as the code for example and also to practice. It should be a bit detailed and like to print the odd numbers or print "hellp world." Can anyone help to suggest if there is an example of code that is a bit detailed with a kind of complex problem which will give students a hands good example? I see a nice example at this link: http://tucano.tucanowebdesign.com/oracle/tutorial5.html - on an inventory system. It gives the feeling of being one on the issue of real-world work. So that if anyone knows of some other example say about 150 t0 300 lines or so of the code, I'll be grateful if it is shared.

    Thank you

    OrauserN

    That said, I feel again (my perception) that more code a person writing/comments the better he gets. So, I want students to examine several code examples. I guess I need to see some books to bring out some really long piece of PL/SQL - like case studies.

    . . .
    But these guys are too busy and so I try to find the net / books some really detailed examples.

    But you seem to be overlooking that PL/SQL is supposed to be used for: PL means "procedural language.

    So, PL/SQL must be used to 'procedure' treatment; This is typically several process steps. For example, when you want to run three applications as a "TRANSACTION". If all three completed successfully you COMMIT and if any of the three you don't ROLLBACK.

    You can do this by using SQL only. And a developer doesn't have to write the code until they have a technical requirements doc that explains what problem the code is supposed to solve and the constraints and requirements that the code must implement.

    So, my suggestion is the following:

    1. identify and teach the types of issues that PL/SQL is used to help solve. Multi-step transactions, I mentioned above is an example

    2. use the documentation and the code of your own organization in the form of samples. These 'guy' is perhaps too busy, but they should be able to provide to you all the documents for the code they wrote and that you use which would be good to use as examples. If they have no documents technical requirements so you just identify a MAJOR gap in the operations of your org that you must bring to the attention of management.

    3. you can provide value added a lot more if you use code from your own org as a basis for what you are doing. A very useful training exercise is to ask students to perform 'code review' of a code (a procedure or function) and write simple comments, one line that explain, in plain English, what makes each piece of code.

    4 comments, students create to step #3 can actually be incorporated into your code then existing so that future developers can use these comments to understand what the code actually does.

    5 part of your 'education' should be on the way to 'test' correctly a piece of code PL/SQL to make sure it is doing what it is supposed to do. Again, if your students actually your own org code allows to create tests, these tests can then be added as a result of 'test' for this application and that adds value. A lot of times those developers 'busy' will not create the actual test cases and that your students can help remedy that. In addition, it does no good to know how to write PL/SQL code if you don't know how to test properly.

  • PL/SQL code help

    Morning all,

    I need assistance with regard to the PL/SQL code.

    Question: How many cases was activated from Direct treatment information/advice within 8 weeks?

    Sample data:

    MEMBER_IDCASE_IDSP_CODESP_NAMESP_SUBTYPE_CODESP_SUBTYPE_NAMEREFERRAL_DATESERVICE_DATE
    00000000120138581001Info & advice1001Information-25/09/2012
    00000000120138581005Direct treatment1022Seamless10/01/201210/01/2012

    I need to count the number of the place where CASE_ID SP_CODE = '1001 ' and then a SP_CODE = '1005' as the program installation, then the difference between SERVICE_DATE for ' 1001' and for '1005' REFERRAL_DATE is within 8 weeks? I hope this makes sense?

    Hello

    One way is to use a Sun-query EXISTS, like this:

    SELECT COUNT (case_id) AS cnt - or COUNT (DISTINCT case_id)

    FROM table_x m

    WHERE sp_code = 1005

    AND THERE ARE)

    SELECT 1

    FROM table_x

    WHERE sp_code = 1001

    AND case_id = m.case_id

    AND service_date > = m.service_date - (8 * 7)

    AND service_date< >

    )

    ;

    I hope that answers your question.

    If not, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.  Point where the query above will not and explain how to get good results in these places.

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

    The combination (case_id, sp_code) is unique?  What happens if a case_id has, say, 1001 multiple s all less than 8 weeks before the same 1005?

    Member_id (or one of the other columns not in the above query) plays no role in this problem?

Maybe you are looking for