Need sql code

Hi All,
I have table data like this....
select 1 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'30-JUN-12' LDATE FROM DUAL
UNION
select 1 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUL-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
UNION
select 2 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
UNION
select 3 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'31-MAY-13' LDATE FROM DUAL
UNION
select 3 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
UNION
select 4 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'31-JUL-13' LDATE FROM DUAL
UNION
select 4 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
UNION
select 5 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'31-MAY-13' LDATE FROM DUAL
UNION
select 5 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-SEP-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
the output condition like
Case 1     Email has 2 Manager records with the same SDate
Case 2     email has 2 Manager records with the same EDate
Case 3     email has 2 Manager records with overlapping dates
Here i need required out out the below mentioned only......
select 3 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'31-MAY-13' LDATE FROM DUAL
UNION
select 3 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
UNION
select 4 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'31-JUL-13' LDATE FROM DUAL
UNION
select 4 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
UNION
select 5 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-JUN-12' SDATE,'31-MAY-13' LDATE FROM DUAL
UNION
select 5 ID,'[email protected]' EMAIL,'[email protected]' MGRMAIL,'01-SEP-12' SDATE ,'31-MAY-13' LDATE FROM DUAL
Please hlep me out....
-------------------------------I have tried...but somthing i am in wrong way.PLease help me out...bit critical..
select ID,
EMAIL,
MGRMAIL,SDATE, LDATE
from (
select ID,
EMAIL,
MGRMAIL,
SDATE, LDATE,
count(distinct MGRMAIL) over(partition by ID, EMAIL) cnt_ALL,
count(*) over(partition by ID, EMAIL, SDATE) cnt_FROM,
count(distinct MGRMAIL) over(partition by ID, EMAIL, SDATE) cnt_FROM_mgr,
count(*) over(partition by ID,EMAIL,LDATE) cnt_TO,
count(distinct MGRMAIL) over(partition by ID,EMAIL,LDATE) cnt_TO_mgr,
FROM s_data
where ( ((cnt_ALL =2) and (cnt_FROM = cnt_FROM_mgr OR cnt_TO=cnt_TO_mgr OR cnt_FROM != cnt_FROM_mgr OR cnt_TO!=cnt_TO_mgr))
Edited by: anbarasan on Sep 16, 2012 10:04 PM

anbarasan wrote:
Hi All,
i have tried using this query....but looks not correct please have look and solve ..
select ID,
EMAIL,
MGRMAIL,SDATE, LDATE
from (
select ID,
EMAIL,
MGRMAIL,
SDATE, LDATE,
count(distinct MGRMAIL) over(partition by ID, EMAIL) cnt_ALL,
count(*) over(partition by ID, EMAIL, SDATE) cnt_FROM,
count(distinct MGRMAIL) over(partition by ID, EMAIL, SDATE) cnt_FROM_mgr,
count(*) over(partition by ID,EMAIL,LDATE) cnt_TO,
count(distinct MGRMAIL) over(partition by ID,EMAIL,LDATE) cnt_TO_mgr,
FROM s_data
where ( ((cnt_ALL =2) and (cnt_FROM = cnt_FROM_mgr OR cnt_TO=cnt_TO_mgr OR cnt_FROM != cnt_FROM_mgr OR cnt_TO!=cnt_TO_mgr))why should we provide answer when you never acknowledge any responses from here?

Similar Messages

  • Need SQL code for this logic - -  From Serial and To serial no.

    In Forms 4.5 Screen I have two text boxes where i will be entering From Serial No
    and to serial no.
    I want the code which will check whether any number in between these from and to serial exists in a table or not ?
    For Example
    Select * from t; -- contains
    serial number
    321-456-789
    123-456-654
    321-569-986
    321-569-987
    When I enter from Serial no 321-456-789 and to serial no as 321-456-789.. I should get a message sayinig that 321-456-789 exists.
    When I enter from Serial no 321-569-986 and to serial no as 321-569-988.
    I should get a message sayinig that 321-456-986 exists.
    I should get a message sayinig that 321-456-987 exists.
    I should get a message sayinig that 321-456-988 not exists.
    is it possible with a SQL query or do we need to go for procedure or temp table ?
    If anybody ahving similar code please post it here.
    Thanks in Advance
    Devender

    Hi Devender,
    Try this :
    SQL> select * from t;
    SN
    321-456-789
    123-456-654
    321-569-986
    321-569-987
    SQL> var sn1 varchar2(11)
    SQL> exec :sn1 := '321-569-986'
    Procédure PL/SQL terminée avec succès.
    SQL> var sn2 varchar2(11)
    SQL> exec :sn2 := '321-569-988'
    Procédure PL/SQL terminée avec succès.
    SQL>1  select a.sn, decode(t.sn,null,'does not exists','already exists')
      2  from
      3  (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
      4        ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
      5        ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
      6  from (select level
      7        from dual
      8        connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
      9       )
    10  )a,
    11  t
    12* where a.sn=t.sn(+)
    SQL> /
    SN                            DECODE(T.SN,NUL
    321-569-986                   already exists
    321-569-987                   already exists
    321-569-988                   does not exists
    SQL> exec :sn1 := '321-456-789'
    Procédure PL/SQL terminée avec succès.
    SQL> exec :sn2 := '321-456-789'
    Procédure PL/SQL terminée avec succès.
    SQL> l
      1  select a.sn, decode(t.sn,null,'does not exists','already exists')
      2  from
      3  (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
      4        ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
      5        ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
      6  from (select level
      7        from dual
      8        connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
      9       )
    10  )a,
    11  t
    12* where a.sn=t.sn(+)
    SQL> /
    SN                            DECODE(T.SN,NUL
    321-456-789                   already exists
    SQL> Nicolas.

  • HELP: Need SQL code for bulk move

    I am using Oracle 11.2, there are two tables tb_base, tb_hist as following:
    tb_base (id number(5), tag varchar2(16), setTs timestamp(6));
    tb_hist(id number(5), histTs timestamp(6), setTs timestamp(6), tag varchar2(16));
    tb_base 1, 'adsf', 2012/12/20
    1, 'bbb', 2012/12/08
    1, 'ccc', 2012/12/30
    2, 'aaa', 2012/11/29
    2, 'vvv', 2012/11/28
    All I need is to move non-latest record with the same id from tb_base to tb_hist as followings:
    tb_base 1, 'ccc', 2012/12/30
    2, 'aaa', 2012/12/29
    tb_hist 1, 'adsf', 2012/12/20, 2012/12/20
    1, 'bbb', 2012/12/08, 2012/12/08
    2, 'vvv', 2012/11/28, 2012/11/28
    Any suggestion on the SQL to complete this task?
    Thanks

    Copy the historical records to TB_HIST:
    INSERT INTO tb_hist
    (id
    ,histts
    ,setts
    ,tag)
    SELECT id,
           setts,
           setts,
           tag
    FROM   tb_base a
    WHERE EXISTS (SELECT 1
                  FROM  (SELECT id,
                                MAX(setts) OVER (PARTITION BY id) max_setts
                         FROM   tb_base) b
                  WHERE  b.id         = a.id
                  AND    b.max_setts != a.setts)Delete the historical records from TB_BASE:
    DELETE tb_base a
    WHERE EXISTS (SELECT 1
                  FROM  (SELECT id,
                                MAX(setts) OVER (PARTITION BY id) max_setts
                         FROM   tb_base) b
                  WHERE  b.id         = a.id
                  AND    b.max_setts != a.setts)

  • Need PL/SQL code for this

    Hi,
    I need a PL/SQL code for this one...
    Let me know if something is not clear...
    1) The table CLOB_CLOBJECT_CDA has the columns described below...
    Explaining only those fields which are important in this context
    -- CDA_STEP_ID : Basically a Sequence
    -- CLOBJECT_SOURCE1_ID : Every id has got a set of records
    -- CLOBJECT_SOURCE2_ID : Every id has got a set of records
    -- LVL : There are total 8 levels..
    This is the main aim :
    1) There are total 16 million rows..(limited to 10 rows here)
    2) We need to go through level by level (LVL column) & insert the intersection records (CLOBJECT_SOURCE1_ID intersect CLOBJECT_SOURCE2_ID)
    into another table...but this is how it goes..
    Level (LVL column) 3's basically have CLOBJECT_SOURCE1_ID as level (LVL column) 2 CDA_STEP_ID's..
    (consider the statement --** where CLOBJECT_SOURCE1_ID = 285 which is same as 1st insert statement step id)..
    The above process goes for next levels until 8..(so have to use loops)
    So for ex :
    We go through the first insert statement and insert the insertion records only when both CLOBJECT_SOURCE1_ID & CLOBJECT_SOURCE2_ID has got records ..
    If we don't find any records for both of them we should skip the corresponding step id when we go to the next levels...
    Let's go through the 1st insert statement...
    -- We have CDA_STEP_ID = 285 & two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 74...
    -- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 74 ..(In fact we insert counts into this table only if they have records)
    -- If so, we insert the intersection records into CDA_MRN_RESULTS ( we do have counts for both of them..) with CDA_STEP_ID 285...
    -- Then we insert the step id which is 285 along with the count into CLOBJECT_COUNTS..
    Let's go through another insert statement...
    -- Consider CDA_STEP_ID = 288 which has two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 92...
    -- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 92 ..(we have records for 19 but not for 92)
    -- So we should not proceed with this..& also skip all those records (future records with increasing levels..basically level 3's) which have got 288 as CLOBJECT_SOURCE1_ID..
    (As said earlier that the present CDA_STEP_ID will always be CLOBJECT_SOURCE1_ID in the next level)...
    I wrote the following code which is after the statement...
    Let me have the create & insert statements here..
    create table CLOB_CLOBJECT_CDA
        CDA_STEP_ID           NUMBER,
        CDA_ID                NUMBER,
        CDA_SEQ_NUMBER        NUMBER,
        CLOBJECT_SOURCE1_TYPE VARCHAR2(3000),
        CLOBJECT_SOURCE1_ID   NUMBER,
        CLOBJECT_OPERATOR     VARCHAR2(3000),
        CLOBJECT_SOURCE2_TYPE VARCHAR2(3000),
        CLOBJECT_SOURCE2_ID   NUMBER,
        LVL                   NUMBER
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (285, 285, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 74, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (286, 286, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 75, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (287, 287, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 91, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (288, 288, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 92, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4869, 4869, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 91, 3);  -- **
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4870, 4870, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 92, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4871, 4871, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 93, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4880, 4880, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 91, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4881, 4881, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 92, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4882, 4882, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 93, 3);
    create table CDA_MRN_RESULTS
       CDA_STEP_ID      NUMBER,
      MRN              NUMBER,
      INSERT_DATE_TIME DATE
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (19, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (19,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (19,  3, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (74,  1, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (74,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (74,  4, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (75,  1, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (75,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (75,  6, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (91,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (91,  3, to_date('19-10-2011', 'dd-mm-yyyy'));
    create table CLOBJECT_COUNTS
      CDA_STEP_ID    NUMBER,
      CLOBJECT_COUNT NUMBER,
      DATE_TIME      DATE
    Insert into CLOBJECT_COUNTS values (19,3, to_date('19-10-2011', 'dd-mm-yyyy'));
    Insert into CLOBJECT_COUNTS values (74,3, to_date('19-10-2011', 'dd-mm-yyyy'));
    Insert into CLOBJECT_COUNTS values (75,3, to_date('19-10-2011', 'dd-mm-yyyy'));
    Insert into CLOBJECT_COUNTS values (91,2, to_date('19-10-2011', 'dd-mm-yyyy'));The output goes into two tables...
    CDA_MRN_RESULTS : O/p of intersection records between source1 & source2 id
    CLOBJECT_COUNTS : Step id with counts ...(useful for skipping next level step id's if either of source id has "0" counts)
    Any help is appreciated..
    Thanks..

    I tried to code this..but looping takes a lot of time..I want to skip certain rows where source1_step_id & source_2_step_id are not in clobject_counts table as we proceed to the next levels..Not sure how to skip the rows..
    declare
    cursor c1 (p_level varchar2 ) is
      Select * from clob_clobject_cda
        where lvl = p_level    ;
       TYPE V_TT IS TABLE OF C1%ROWTYPE INDEX BY PLS_INTEGER;
        L_TT V_TT;
        v1 number;
        v2 number;
        v_step_id number;
        v_operator varchar2(100) := '';
    begin
    for i in 2..8 loop
      open c1(i);
      LOOP
           FETCH C1 BULK COLLECT INTO L_TT LIMIT 500;
            FOR indx IN 1 .. L_TT.COUNT
             LOOP
               v1 := L_TT(indx).clobject_source1_id;
               v2 := L_TT(indx).clobject_source2_id;
               v_step_id := L_TT(indx).cda_step_id;
               v_operator := L_TT(indx).clobject_operator;
      Execute Immediate ('Insert into cda_mrn_results Select --+ parallel (cm 128)
                                                      distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results  cm
                        where cda_step_id = ' || v1 || '
                        and   cda_step_id in (Select cda_step_id from clobject_counts) ' ||
         v_operator ||
                    '  Select --+ parallel (cm 128)
                                                      distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results  cm
                        where cda_step_id = ' || v2 || '
                        and   cda_step_id in (Select cda_step_id from clobject_counts)  ' );
    Insert --+ Append
           into clobject_counts Select cda_step_id, count(distinct mrn),
                       insert_date_time dt from cda_mrn_results  where cda_step_id =  v_step_id   group by cda_step_id,insert_date_time;
       COMMIT;                    
             END LOOP;
           EXIT WHEN L_TT.COUNT = 0;
         END LOOP;
      CLOSE C1;
    End Loop;    
    Commit;
    End;

  • Need pl/sql code to Encrypted data to decryption formate

    Hi All,
    I have Encrypted data 64 bit formate like
    encrypt
    780D0287
    FA57C55510D258C73DE93059E3DC49EC
    need output as a Decryption data..kindly give me output

    This is your duplicate post...
    Re: Need pl/sql code to decryption
    *009*

  • Need way to Wrap my PL/SQL code

    Hi
    How can I Wrap my PL/SQL code ?
    The current Wrap.exe can be Hacked easily using this site http://hz.codecheck.ch/UnwrapIt/Unwrap.jsp.
    what is the best way to hide Wrap my PL/SQL code in DB.
    Thanx
    Rafeek Abd Elmonsef

    reemax wrote:
    please where can I download "plsql developer 10g version 2000 release 10.2.0.2"There's no point downloading a GUI to do it for you, all that does is call the Oracle WRAP functionality.
    There's only the one way to wrap PL/SQL code. Just because it can be unwrapped doesn't mean that everybody will have the ability to unwrap it. If you're really that concerned about people getting your source code then you shouldn't release it in any format. At the end of the day, if it's packages that are being supplied to a customer, wrap them and have appropriate copyright and reverse engineering agreements in place, then if your code gets stolen, you can take legal action.
    You can get some tools (I've seen them but never used them) that help to anonymise your code, by renaming all the variables etc. to nonsensical ones such as a,b,c,d etc. (just like some people's coding I've seen LOL!), so if you were to do that and then wrap the code, if anyone does unwrap it, it will be harder for them to understand what the code actually does.

  • PL/SQL code written in db or in application...????

    Hi ,
    Which is the best...at performance , maintability... e.t.c.???
    To write PL/SQL as validation process of data values going to be inserted in db:
    1) as db trigger (before insert or update row-level trigger)
    2) in application level - in Forms10g...
    This PL/SQL code compares some pairs of data values only.... there DML statement....
    Both db server and App server are considered to be or in the same machine or in two machines very close to each other...
    Note: i use Db10g .
    Thanks...
    Sim

    It is all about moving parts. How many there are. Where they are located.
    The less moving parts, the less the complexity, the bugs - and the better the performance (less wheels to turn to crunch data), the easier the maintenance and the better the flexibility.
    Part of this is having the moving parts close to the data. Kind of obvious - what is faster? Shipping data from the db engine to a front-end application via a app server and web server? Or shipping the data from the db (SQL) engine to a PL/SQL process running as part and parcel of db instance? IPC is significantly faster than TCP/IP.
    Having the moving parts close to the data also means that it can scale with the data. Oracle is good at scalability. It is designed at its very core to be scalable. Partitions to reduce I/O. Shared Server to reduce o/s resource footprint per client session. Shared pool to re-use SQL. DB buffer to cache data. RAC to run multiple db instances for a single physical database. Etc. Etc.
    With the application moving parts being close to the data, it inherits this scalability. You can "multi-thread" application code using table pipelines. You have access to forking application code using background processes (DBMS_JOB and DBMS_SCHEDULER). You have bulk processing in order to transfer more data per SQL engine call, between the buffer cache and your application, and thus also reduce expensive context switching.
    This list goes on and on.
    All this is summarised into the following rules.
    Rule 1. Do it in SQL.
    Rule 2. Only when SQL cannot do it, use PL/SQL. (e.g. SQL is not suited for managing and controlling process flow - PL/SQL is)
    Rule 3. Only when PL/SQL cannot do it, use <insert-language-here> (e.g. PL/SQL cannot render a Windows grid on the client - but Delphi/C#//Java can).
    Also keep in mind that in the modern client-server paradigm we deal with a web architecture. Which means the client is a web browser. And this means that PL/SQL can pass the data (HTML) required by the client (web browser) to render the User Interface.
    Have a look at APEX (Oracle's Application Express) for how this works. http://apex.oracle.com
    All you need to develop web applications is APEX (a PL/SQL product suite in the database) and a web browser. Kickass stuff... :-)

  • REPORT WITH PL/SQL  CODE

    DECLARE
    SQ VARCHAR2(100);
    BEGIN
    SQ := 'SELECT * FROM EMP WHERE EMPNO=7788';
    RETURN SQ;
    END
    THE ABOVE PL/SQL CODE WORKING FINE
    BUT I NEED CONDITION BASED ON ENAME
    SQ:='SELECT * FROM EMP WHERE ENAME=''SCOTT'';
    IT IS GIVEING ERROR
    WHAT TO DO?

    Hi,
    You're missing the final quote - you have the quotes for SCOTT but not the one to close the SQ string:
    DECLARE
    SQ VARCHAR2(100);
    BEGIN
    SQ := 'SELECT * FROM EMP WHERE EMPNO=''SCOTT''';
    RETURN SQ;
    ENDAndy

  • How to 100% Protect PL/SQL Code By Wrapped in Oracle Database 10g R2

    Hello,
    Is Possible to 100% Protect PL/SQL Code By Wrapped in Oracle 10g R2 ?
    If it is not possible by wrap in oracle 10g R2,
    Please, let me suggest, how i will be able to 100% protect PL/SQL code in Oracle Database 10g R2.
    Because, I have lot of functions, procedures & package's in my project.
    Which is running in field filed.
    So, i have needed to protect 100%.
    Also, will i convert to al functions, procedures & package's to .pll file ?
    And .pll file to .plx file?
    Is it possible to convert .plx file to .pll file ?
    Please, let know any better solutions in this case....
    Regards
    Mehedi

    Hello,
    No, wrapping is not a 100% secure method. It could prevent your code from amateurs, but not from professional hackers. Look at the article http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/wrap.htm#BEHGBJAA
    It says: "•Wrapping is not a secure method for hiding passwords or table names.
    Wrapping a PL/SQL unit prevents most users from examining the source code, but might not stop all of them."
    Edited by: apiminov on 03.12.2012 3:23
    Edited by: apiminov on 03.12.2012 3:24

  • PL/SQL Code not working without debug statements

    Hi Guys,
    I have a pl/sql code in a procedure, logic iterates through almost 40K records, conditional delete and update.
    When I execute this code, I dont see the deletes and updates happening, though procedure executes for 8 minutes and exits wihtout any error, execption.
    In same procedure when I write some debug statements like dbms_output, then everything seems to be working fine.
    I know this scenario happens in Oracle Forms, wehre we use SYNCHRONIZE.
    But this is plain pl/sql procedure.
    any thoughts on this?
    Av.

    COMMIT ?
    Aside from that, no idea what your procedure looks like, what it does, what version of Oracle you are using, how you are determining "I dont see the deletes and updates happening". etc...
    You'd need to provide a slew of information for anyone to give you any meaningful help.
    I can only assure you that DBMS_OUTPUT doesn't do magic :)

  • Can I have a PL/SQL code for LOV

    Hi,
    I apologize for this dumb question. I have been so out of touch with dev (almost 8 years). Plus new to pl/sql.
    I am creating a status report application. On the dashboard, I currently have some metrics (horizontal charts). I wanted to expose these metrics based on filter.
    I had created 2 filters. The first one will identify the type (Week, Month, Qtr or Year) and the 2nd filter would be based on the type. For e.g. if I select Month as type, the 2nd filter should show May-12, April-12 etc. Once I select the 2nd filter, I should use them to show the appropriate metrics. The metric that I currently have would show all the projects that users have worked on during the week/month/qtr or year (depending on the 1st and 2nd filter).
    On the dashboard region, I added a condition to check if the value for both 1st and 2nd filter is not null. This allows me to show the dashboard only if the 2 filters have been selected.
    For the 2nd filter, I need to write a PL/SQL code to show the LOV.
    I am assuming that the pl/sql would return a SQL query. The SQL query will be based on week, month etc. Is that right?
    Thanks
    balaji
    Edited by: user644868 on May 17, 2012 11:29 AM

    rbalaji2026 wrote:
    For the 2nd filter, I need to write a PL/SQL code to show the LOV. Doesn't appear necessary. With filter 2 cascading from filter 1, why not:
    select
            /* Week query */
    from
    where
    and     :p1_filter_1 = 'WEEK'       
    union all
    select
            /* Month query */
    from
    where
    and     :p1_filter_1 = 'MONTH'       
    union all
    select
            /* Quarter query */
    from
    where
    and     :p1_filter_1 = 'QUARTER'       
    union all
    select
            /* Year query */
    from
    where
    and     :p1_filter_1 = 'YEAR'       

  • How can one  read a Excel File and Upload into Table using Pl/SQL Code.

    How can one read a Excel File and Upload into Table using Pl/SQL Code.
    1. Excel File is on My PC.
    2. And I want to write a Stored Procedure or Package to do that.
    3. DataBase is on Other Server. Client-Server Environment.
    4. I am Using Toad or PlSql developer tool.

    If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
    1. Get your DBA to create directory object in oracle using the following command:
    create directory TEST_DIR as ‘directory_path’;
    Note: This directory is on the server.
    2. Grant read,write on directory directory_object_name to username;
    You can find out the directory_object_name value from dba_directories view if you are using the system user account.
    3. Logon as the user as mentioned above.
    Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
    function getData(p_filename in varchar2,
    p_filepath in varchar2
    ) RETURN VARCHAR2 is
    input_file utl_file.file_type;
    --declare a buffer to read text data
    input_buffer varchar2(4000);
    begin
    --using the UTL_FILE in built package
    input_file := utl_file.fopen(p_filepath, p_filename, 'R');
    utl_file.get_line(input_file, input_buffer);
    --debug
    --dbms_output.put_line(input_buffer);
    utl_file.fclose(input_file);
    --return data
    return input_buffer;
    end;
    Hope this helps.

  • APEX,PDF's, BI Publisher and SQL Query returning SQL code..

    I don't know if I should be posting this in this Forum or the BI Publisher forum, so I am posting in BOTH forums..
    I love APEX, let me say that first.. And appreciate the support offered here by the group, but am running int a confusing issue when BI Publisher tries to build a report from the above type APEX report..
    Here is my dilemma:
    I have a number of reports that are part of a Oracle package. They return an SQL Query back to a reports region on a page. I am having to deal with the column names returned are col01, col02..
    The issue I have is, when building the Application Level query to download the XML sample from in building RTF layouts in Word, you can not use this code, you MUST use a standard SQL Select.
    I have taken the sql from the function returning sql, and copied into the application query, supplying the required data values for bind variables being used in the query.
    An XML file is produced, and I use this to build the RTF format file that I load back into APEX and try to use it for the PDF rendering of the report. I can view the output as a PDF in the Word add on, but when I try using it with the report, it is returning an empty PDF file.
    Can anyone tell me what error log files on the bi publisher side I can look at to see what error is happening?
    Thank you,
    Tony Miller
    UTMB/EHN
    Title adjusted to allow people to know what I am talking about...
    Message was edited by:
    Tony Miller

    Tony,
    You can find the log as follows:
    - go to http://[yourserver]:[yourport]/em
    - logon to OC4J EM: oc4jadmin/[yourpassword]
    - click on "logs" at the bottom of the page
    - in the hgrid/tree, expand OC4J->home->Application
    xmlpserver
    - click on view log icon
    You can also observe what's going on in BI Publisher
    by going to the command prompt from where you started
    it.
    Or, as a third option, you can locate the file on
    your file system, depending on your setup, the path
    would be something similar to this:
    \oracle\product\10.2.0\bip\j2ee\home\application-deplo
    yments\xmlpserver\application.log
    With that said though, I don't expect you'll find
    much in there that would help with your particular
    problem. I suspect you either get no rows in your XML
    at runtime, due to some session state issues, or your
    XML structure does in fact not match your RTF
    template.
    I'm not quite following your problem description,
    i.e. when did you do what and are you associating
    your report layout with a report query or report
    region. So just some general notes, your query needs
    to be parseable at design-time, when exporting the
    XML, so that you get the XML file with the proper
    column names derived from your query. If you want to
    use your RTF template with a standard report region,
    you must export the XML file first using the advanced
    XML structure option. And of course the column names
    in your report query need to match the column names
    in your report region.
    Perhaps this helps you further diagnose what's going
    on, if you have additional information that could
    help, let me know. And if you could stage this on
    apex.oracle.com, I'd be happy to take a look.
    Regards,
    MarcMarc,
    Thanks for looking at this issue. Below find my remarks to your questions..
    Re: your query needs
    to be parseable at design-time, when exporting the
    XML, so that you get the XML file with the proper
    column names derived from your query.At the start of this process, the query code was a function in a package. The function was returning an SQL select statement, for a report region on a page. I took the select statement, built an application query to build a sample of the xml for BI Publisher desktop (Add-on for Word). The code was producing the usual Col01, Col02.. since at design time that is were the column names.
    When I then took the xml from this and built the rtf for loading into my APEX application.
    When testing the Application Query with this RTF report layout, I am getting PDF's. When using it with the report region sending an xml feed to BI Publisher I am getting nothing back.
    I have since taken the sql code and moved it back into the report region, and set the region to have a type of straight SQL Query. I have even tried to hard-code the parameters I was getting from the page to limit data returned.
    Is it possible to see the xml being produced by the APEX page?
    Re: Stage this on apex.oracle.com.. I would love to, but we would have HIPPA issues if I posted the data on a public website.
    Can I send you the RTF file and the xml file that the application query is creating to see if there something weird about them?
    Thank you,
    Tony Miller
    UTMB/EHN

  • I need the code to delete record in the database not in the form???

    I need the code to delete record in the database not in the form...
    because when i execute a form always insert the datas in the data base but i want insert value on a text file and delete in the data base the record whith this value of text file.
    i'm spanish an my english is bad sorry.
    thank, javier

    Well, I fail to understand why you want to complicate easy things, but anyway you can do that by using TEXT_IO within Forms to create text file (see Forms builder help), and UTL_FILE package to read it within Pl/Sql : you could create a stored procedure, and call it from Forms passing the file name as parameter. See UTL_FILE documentation

  • Can I create a file using pl/sql code in application server ?

    Hi
    I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?
    Please help me with an example...in this regard
    Regards
    Sa

    864334 wrote:
    I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?And how is this "file" to be delivered?
    Files can be created by PL/SQL code and stored in the Oracle database as CLOBs. This a fairly easy and robust process. It runs entirely in the database. It conforms to transaction processing. The "file" (as a CLOB) resides in the database and can thus be secured via database security, is part of database backups and so on.
    The basic issue is how to deliver the contents of the CLOB to the user. If via FTP, then the database can directly FTP the contents of the CLOB to the FTP server as a file. If via HTTP, the database can deliver the CLOB as a HTTP download directly to the web browser.
    If the client is Java or .Net, then the CLOB contents can be delivered via SQL or DBMS_LOB or a custom PL/SQL interface.
    In such cases, there is no need to step outside the secure and flexible database environment and create a physical o/s file in the wild (outside the controls of database security, data integrity and transaction processing). This is thus recommended and is the preference.

Maybe you are looking for

  • Moving hard drive from iMac G5 to eMac 700Mhz

    Hi, Hard drive in my eMac failed recently and on the top of that iMac G5 logic board stopped working (known problem). Now I wonder if I could move over iMac's hard drive (and Airport card) with 10.4 on it to my eMac. Is that possible? Or do I have to

  • Why is the Java runtime resource hungry and slow?

    Hi, First of all let me make it clear that I'm not here to bash Java. I'm a big fan of the technology. In fact I believe in its potential as it is the only true 100% cross-platform runtime. Now that it has been open sourced, it has just made me happi

  • MacBook Pro woes...

    I've had my MacBook Pro for about 8 months now. Generally it's been all round very good but only in the last couple of months has it developed a whole range of problems. The DVD drive frequently locks up refusing to eject disks and cannot burn disks

  • Preparing AD for 2012

    Greetings, We are getting ready to add 2012 member servers to our network. Specifically, we're adding a server to use for DFS and for file services. The 2012 server will act as the namespace server and will be the hub for some 2003 & 2008 replication

  • Upgrading to new iCal has deleted all my calendars on all my synced Macs

    20 minutes ago I responded to a software upgrade for iCal. After I did so and synced, I now have no calendars on any Mac - it has wiped everything out. Beware!!!