problem with a query with clause

Hello

I am facing a problem, so I describe a little:
create table schoolboys (
id integer,
name varchar2(20)
/

create table marks (
schoolboy_id integer,
mark integer,
mark_type char(1))
/

create table avg_marks (
schoolboy_id integer,
avg_mark number (5,2)
)
/


insert into A values (50, 9, 'N');
insert into A values (50, 7, 'N');
insert into A values (50, 6, 'T');
insert into A values (88, 9, 'N');
insert into A values (88, 7, 'N');
insert into A values (88, 10, 'T');
insert into A values (20, 4, 'N');
insert into A values (20, 5, 'N');
insert into A values (20, 3, 'N');
insert into A values (20, 5, 'T');
and I make this request for several insertion in another table
INSERT INTO avg_marks 
           (schoolboy_id, 
            avg_mark) 
(SELECT   schoolboy_id, 
          (Avg(Decode(mark_type,'T',NULL,
                                mark)) * 3 + Sum(Decode(mark_type,'T',mark, 
                                                                  0))) / 4
 FROM     marks 
 GROUP BY schoolboy_id);
But what I want is to insert in avg_marks that records where the
((Avg(Decode(mark_type,'T',NULL,
                                mark)) * 3 + Sum(Decode(mark_type,'T',mark, 
                                                                  0))) / 4) > 5
So, I want to limit inclusion in avg_marks.
If there are results with (avg (decode...)) < 5 these files, I want to be inserted into another table, with the same columns as avg_marks
How should I code this? What should I use?
I tried with
with t as(
(SELECT   schoolboy_id,
          ((Avg(Decode(mark_type,'T',NULL,mark)) * 3 
          + Sum(Decode(mark_type,'T',mark,0)) / 4))>5) MARK
from MARKS
)
INSERT INTO avg_marks
           (schoolboy_id,
            avg_mark) values (t.schoolboy_id, t.MARK)
 
ORA-00923: FROM keyword not found where expected
Best regards

Edited by: Roger22 the 18.06.2009 11:36

fix

No, not at all sure you insert records into a table, then another! ;) Do you mean an multi-table insert, i.e. two INSERTs in the transaction?

INSERT FIRST
  WHEN avg_mark >= 5 THEN
    INTO avg_marks (schoolboy_id,  avg_mark)
    VALUES (schoolboy_id, avg_mark)
  WHEN avg_mark < 5 THEN
    INTO avg_marks2 (schoolboy_id,  avg_mark)
    VALUES (schoolboy_id, avg_mark)
  SELECT   schoolboy_id,
          (Avg(Decode(mark_type,'T',NULL,
                                mark)) * 3 + Sum(Decode(mark_type,'T',mark,
                                                                  0))) / 4 avg_mark
    FROM     marks
 GROUP BY schoolboy_id;

Tags: Database

Similar Questions

  • Problem with order by clause

    Hai all,

    I have problem with order by clause,

    My query is

    "Select number from table1 order number CSA.

    and the output as

    1
    10
    12
    13
    15
    17
    19
    2
    20
    21
    22
    .
    ........

    But if we give the order that it should display below the only good?

    1
    2
    10
    12
    13
    15
    17
    19
    20
    21
    22 ........

    Help me please why it is not displayed as she. and how to make the statement to display as in the second case. Thanks in advance.

    Kind regards
    Uraja

    In your table, the column is VARCHAR2 data type.

    It is a string, even if it is to store numeric values, it will get condemn as strings

    Try the below

    select your_column from table1 order by to_number(your_column) asc 
    

    Published by: JAC on November 19, 2012 16:35

  • Problem with pseudo-HIERARCHICAL query

    Hi all

    I'm writing a piece of SQL to validate the check digit in wines

    (http://en.wikipedia.org/wiki/Vehicle_identification_number#Check_digit_calculation)


    using
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production


    The logic in the wikipedia article can be encapsulated as follows:
    with val as (select '0' ch, 0 val from dual
                 union all
                 select '1', 1 from dual
                 union all 
                 select 'A',1 from dual
                 union all 
                 select 'J',1 from dual
                 union all 
                 select '2',2 from dual
                 union all 
                 select 'B',2 from dual
                 union all 
                 select 'K',2 from dual
                 union all 
                 select 'S',2 from dual
                 union all 
                 select '3',3 from dual
                 union all 
                 select 'C',3 from dual
                 union all 
                 select 'L',3 from dual
                 union all 
                 select 'T',3 from dual
                 union all 
                 select '4',4 from dual
                 union all 
                 select 'D',4 from dual
                 union all 
                 select 'M',4 from dual
                 union all 
                 select 'U',4 from dual
                 union all 
                 select '5',5 from dual
                 union all 
                 select 'E',5 from dual
                 union all 
                 select 'N',5 from dual
                 union all 
                 select 'V',5 from dual
                 union all 
                 select '6',6 from dual
                 union all 
                 select 'F',6 from dual
                 union all 
                 select 'W',6 from dual
                 union all 
                 select '7',7 from dual
                 union all 
                 select 'G',7 from dual
                 union all 
                 select 'P',7 from dual
                 union all 
                 select 'X',7 from dual
                 union all 
                 select '8',8 from dual
                 union all 
                 select 'H',8 from dual
                 union all 
                 select 'Y',8 from dual
                 union all 
                 select '9',9 from dual
                 union all 
                 select 'R',9 from dual
                 union all 
                 select 'Z',9 from dual)
       ,weight as (select 1 pos, 8 weight from dual
                    union all 
                    select 2, 7 from dual
                    union all 
                    select 3, 6 from dual
                    union all 
                    select 4, 5 from dual
                    union all 
                    select 5, 4 from dual
                    union all 
                    select 6, 3 from dual
                    union all 
                    select 7, 2 from dual
                    union all 
                    select 8, 10 from dual
                    union all 
                    select 9, 0 from dual
                    union all 
                    select 10, 9 from dual
                    union all 
                    select 11, 8 from dual
                    union all 
                    select 12, 7 from dual
                    union all 
                    select 13, 6 from dual
                    union all 
                    select 14, 5 from dual
                    union all 
                    select 15, 4 from dual
                    union all 
                    select 16, 3 from dual
                    union all 
                    select 17, 2 from dual)
    I can easily get the check digit for a WINE of the following logic:

        ,vm as (select row_number() over(partition by vin order by level) rn
                       , substr(vin, level,1) v
                       , vin
                    from (select 'ZAR91600006043427' vin
                            from dual
                         )
                 connect by level <= length(vin))
    select vin
         , mod(sum(checksum),11) calculated_check
         , substr(vin,9,1) existing_check
         , regexp_instr(substr(vin,9,1),mod(sum(checksum),11)) correct
      from (select val.val * weight.weight checksum
                  ,vm.vin 
              from vm
              join val on (val.ch = vm.v)
              join weight on (weight.pos = vm.rn)
      order by vm.rn)
    group by vin;
    which produces:
    VIN                              CALCULATED_CHECK                       EXISTING_CHECK                   CORRECT                                
    ZAR91600006043427                4                                      0                                0                                      
    However, I am having a little problem when I try to combine several wines of a table which I want to do rather than calculate each wine by programming:


    This, for example, produces a line for each letter of the wine ready to match with the other two CTES:
    with vehicle as (select 1000 as vehicle_id, 'ZAR91600006043427' as vin from dual
                       union all 
                     select 1001, 'XXX91600006043427' from dual)
    select level
           , substr(vin, level,1) v
           , vin
        from (select *
                from vehicle
               where vehicle_id = 1000
             )
     connect by level <= length(vin);
    I want ideally is a line for each character of each WINE. but this:
    with vehicle as (select 1000 as vehicle_id, 'ZAR91600006043427' as vin from dual
                       union all 
                     select 1001, 'XXX91600006043427' from dual)
    select level
           , substr(vin, level,1) v
           , vin
        from (select *
                from vehicle
               where vehicle_id in (1000,1001)
             )
     connect by level <= length(vin);
    product 262142 lines!

    and adding
    where vin = prior vin
    just reduced to 131070 lines...


    place a different one on the SQL produced the result that I want, but it is not scalable product lines by adding a third vehicle are exponentially more than two.

    so, in short: what is happening with my connect by statement that I'm missing?

    Hello

    Samir says:
    ... I want ideally is a line for each character of each WINE. but this:

    with vehicle as (select 1000 as vehicle_id, 'ZAR91600006043427' as vin from dual
    union all
    select 1001, 'XXX91600006043427' from dual)
    select level
    , substr(vin, level,1) v
    , vin
    from (select *
    from vehicle
    where vehicle_id in (1000,1001)
    )
    connect by level <= length(vin);
    

    product 262142 lines!

    and adding

    where vin = prior vin
    

    just reduced to 131070 lines...

    place a different one on the SQL produced the result that I want, but it is not scalable product lines by adding a third vehicle are exponentially more than two.

    so, in short: what is happening with my connect by statement that I'm missing?

    Whenever you want to debug a CONNECT BY query, put SYS_CONNECT_BY_PATH in the SELECT clause, to see how the lines are related.
    We will also cut the sting down to only 3 characters, in order to make things faster and easier to read and add ROWNUM just to make it easier to talk about the results:

    with vehicle as (select 1000 as vehicle_id, 'ABC' as vin from dual
                       union all
                     select 1001, 'XYZ' from dual)
    select level
           , substr(vin, level,1) v
           , vin
           , sys_connect_by_path ( vin
                        , ','
                        )     AS path_3
           , sys_connect_by_path ( substr (vin, level, 1)
                        , ','
                        )     AS path_1
           , ROWNUM
        from (select *
                from vehicle
               where vehicle_id in (1000,1001)
             )
    -- where     vin     = PRIOR vin
     connect by level <= length(vin);
    

    Output:

    `    LEVEL V    VIN PATH_3               PATH_1         ROWNUM
    ---------- ---- --- -------------------- ---------- ----------
             1 A    ABC ,ABC                 ,A                  1
             2 B    ABC ,ABC,ABC             ,A,B                2
             3 C    ABC ,ABC,ABC,ABC         ,A,B,C              3
             3 Z    XYZ ,ABC,ABC,XYZ         ,A,B,Z              4
             2 Y    XYZ ,ABC,XYZ             ,A,Y                5
             3 C    ABC ,ABC,XYZ,ABC         ,A,Y,C              6
             3 Z    XYZ ,ABC,XYZ,XYZ         ,A,Y,Z              7
             1 X    XYZ ,XYZ                 ,X                  8
             2 B    ABC ,XYZ,ABC             ,X,B                9
             3 C    ABC ,XYZ,ABC,ABC         ,X,B,C             10
             3 Z    XYZ ,XYZ,ABC,XYZ         ,X,B,Z             11
             2 Y    XYZ ,XYZ,XYZ             ,X,Y               12
             3 C    ABC ,XYZ,XYZ,ABC         ,X,Y,C             13
             3 Z    XYZ ,XYZ,XYZ,XYZ         ,X,Y,Z             14
    
    14 rows selected.
    

    There is no START WITH clause, so it will start by each of the 2 rows. It is very good; Take the first case of 'ABC'.
    Level = 1, we have row "ABC", so the substring added to this level is 'A'
    The lines are connected to this line to LEVEL = 2? All rows that satisfy the condition of LEVEL<= length="" (vin),="" which,="" in="" this="" sample="" set,="" means="" both="" rows.="" let's="" take="" 'abc'="" first,="" which="" is="" what="" happened="" on="" the="" line="" where="" rownum="">
    The lines are connected to this line (the line at the end of the path_3 ", ABC, ABC' ') = 3 level? All rows that satisfy the condition of LEVEL<= length="" (vin),="" which,="" in="" this="" sample="" set,="" means="" both="" rows.="" let's="" take="" 'abc'="" first,="" which="" is="" what="" happened="" on="" the="" line="" where="" rownum="">
    So far, so good; the results were exactly what we wanted. But here's where it won't.
    The lines are connected to the line at the end of the path ", ABC, ABC, ABC' level = 4?" All rows that satisfy the condition of LEVEL<= length="" (vin),="" which,="" in="" this="" sample="" set,="" means="" no="" rows.="" so="" let's="" back="" up="" the="" tree="" and="" see="" if="" any="" of="" the="" nodes="" we've="" already="" vistited="" has="" any="" other="" children.="" we="" back="" up="" to="" the="" row="" where="" path_3=',ABC,ABC' does="" 'abc'="" have="" any="" other="" children="" (that="" is,="" rows="" that="" meet="" the="" condition="" 3="">< length="" (vin)?="" yes,="" 'xyz'="" meets="" that="" condition,="" so="" 'xyz'="" is="" a="" child="" of="" 'abc',="" and="" we="" get="" the="" output="" row="" where="" rownum="">

    A CONNECT BY query WHERE clause is applied after the CONNECT BY is done. Adding a WHERE clause only deletes the rows from the result set once they have been generated. If we have a comment the WHERE clause above, the results are:

    `    LEVEL V    VIN PATH_3               PATH_1         ROWNUM
    ---------- ---- --- -------------------- ---------- ----------
             2 B    ABC ,ABC,ABC             ,A,B                1
             3 C    ABC ,ABC,ABC,ABC         ,A,B,C              2
             3 Z    XYZ ,ABC,XYZ,XYZ         ,A,Y,Z              3
             3 C    ABC ,XYZ,ABC,ABC         ,X,B,C              4
             2 Y    XYZ ,XYZ,XYZ             ,X,Y                5
             3 Z    XYZ ,XYZ,XYZ,XYZ         ,X,Y,Z              6
    

    Better, but it is still bad. All the 14 ranks were always generated, and then some of them have been excluded by the WHERE clause.
    Why the lines like the one with ROWNUM = included 3? Because the WHERE 'wine = wine PRIOR' condition is true: on this line, the wine is "XYZ", and wine PRIOR is also "XYZ". The status of research only in the last 2 levels. (PREREQUISITE may only be 1 level.) It does not matter that, earlier in the path, there is a knot where wine! = wine BEFOREHAND; This condition applies only to the finished result set. So the output row with path_3 =', ABC, XYZ "was excluded the result defined by the WHERE clause, but the descendants of this line can remain.

    Moral: If you do a query CONNECT BY and provided to connect BY is 'LEVEL '.<= x",="" then="" the="" table="" had="" better="" have="" only="" one="">
    Odie showed how to use CONNECT BY in this problem, by making the relative to the double CONNECT BY and joining your table of multiple row results.

  • Problem with hierarchical query in function PL\SQL

    I have a simple table containing the ID of the parent

    -Create table

    create the table1 table:

    (

    ID NUMBER (12) not null,

    year number 4.

    month NUMBER (2),

    parent_id NUMBER (12)

    );

    -Create/recreate primary, unique and foreign key constraints

    change the table1 table:

    Add primary key constraint PK_TABLE1 (ID);

    change the table1 table:

    Add the foreign key constraint FK_TABLE1_PARENT (PARENT_ID)

    reference TABLE1 (ID);

    data:

    Insert into TABLE1 (id, year, month, parent_id)

    values (5, 2015, 12, 3);

    Insert into TABLE1 (id, year, month, parent_id)

    values (6 (2015), 12, 4);

    Insert into TABLE1 (id, year, month, parent_id)

    values (3 (2015), 11, 1);

    Insert into TABLE1 (id, year, month, parent_id)

    values (4 (2015), 11, 2);

    Insert into TABLE1 (id, year, month, parent_id)

    values (1, 2015, 10, null);

    Insert into TABLE1 (id, year, month, parent_id)

    values (2 (2015), 10, null);

    commit;

    and query

    with h as

    (select t.id, t.year, t.month, CONNECT_BY_ROOT t.id as parent_id from table1 t

    where t.year = 2015 and t.month = 12

    and CONNECT_BY_ROOT t.year = 2015 and CONNECT_BY_ROOT t.month = 10

    connect by prior t.id = t.parent_id)

    Select * from:

    Join table1 t left t.id = h.parent_id;

    It works, but when I put this request in the procedure pl\sql

    create or replace procedure is get_report (p_cur_out on sys_refcursor)

    Start

    Open the p_cur_out for

    with h as

    (select t.id, t.year, t.month, CONNECT_BY_ROOT t.id as parent_id from table1 t

    where t.year = 2015 and t.month = 12

    and CONNECT_BY_ROOT t.year = 2015 and CONNECT_BY_ROOT t.month = 10

    connect by prior t.id = t.parent_id)

    Select * from:

    Join table1 t left t.id = h.parent_id;             

    end get_report;

    /

    They do not compile. And in the fall, with the exception

    Errors of compilation for the PC of the PROCEDURE. GET_REPORT

    [Error: PL/SQL: ORA-00600: internal error code, arguments: [qctcte1], [0], [], [], [], [], [], [], [], [], []]

    Online: 6

    Text: with h as

    Error: PL/SQL: statement ignored

    Online: 6

    Text: with h as

    My version of oracle

    1Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    2PL/SQL Release 11.2.0.3.0 - Production
    3CORE Production 11.2.0.3.0
    4AMT for Linux: Version 11.2.0.3.0 - Production
    5NLSRTL Version 11.2.0.3.0 - Production

    What is the problem with my request? Or database? How to solve this problem?

    If you have access to MOS, you can search the reason of it. If you are using left join syntax instead of joining ANSI, owner Oracle procedure compiles and returns the result.

  • Problem with insertChildXML, deleteXML, XMLTable query

    Hello

    I'm working on a

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    With partitioning, Real Application Clusters, Automatic Storage Management, OLAP,.

    Options of Data Mining and Real Application Testing

    POWER SUPPLY 11.2.0.3.10

    I have a table with an XMLTYPE field.

    In this area, I insert an object XMLType in this way:

    INSERT INTO t_schedule_alert (id_schedule_alert, id_schedule, i_type_alarm_schedule, id_lang_type_alarm_schedule, id_user, x_alert_type, i_status_schedule_alert, id_lang_status_schedule_alert)

    VALUES (sq_id_schedule_alert.nextval, in_id_schedule, in_i_type_alarm_schedule, 1, id_user_, xml_, ln_schedule_st_alert_waiting, 1)

    RETURN id_schedule_alert INTO id_;

    Where xml_ = XMLtype ("< alert_types >" | ") alert_type_config_ | ("< / alert_types > ') and alert_type_config_ = ' < type > email < / Type > < sms type > < / type > ';

    The insert does not work correctly, infact him select query:

    SELECT MAX (s.id_schedule_alert) id_schedule_alert,
    s.id_schedule,
    s.id_user,
    s.i_type_alarm_schedule,
    Max (s.type_alarm_schedule) type_alarm_schedule,
    Max (s.i_status_schedule_alert) i_status_schedule_alert,
    Max (s.status_schedule_alert) status_schedule_alert,
    Max (s.id_data) id_data,
    Max (decode (his. TYPE_, 'sms', 1, 0)) sms,.
    Email Max (decode (his. TYPE_, 'email', 1, 0))
    Max (decode (his. TYPE_, 'event', 1, 0)) event.
    Expedition Max (decode (his. TYPE_, 'dispatch', 1, 0))
    OF v_schedule_alert s.
    XMLTable ('/ alert_types/type ')
    in passing s.x_alert_type
    path of varchar2 (10) columns type_ "text()".
    ) its
    WHERE s.id_schedule =: b1
    AND s.id_user =: b2
    GROUP OF s.id_schedule, s.id_user, s.i_type_alarm_schedule;

    Works very well in showing me the email = 1 sms = 1, event = 0, = 0 shipping.

    Then, using this function to manipulate the XML:

    -function update_alert

    FUNCTION update_alert)

    in_id_schedule in NUMBERS

    in_i_type_alarm_schedule in NUMBERS

    iv_alert_type IN VARCHAR2,

    in_id_user in NUMBERS

    in_action in NUMBERS

    ) RETURN NUMBER

    IS

    id_user_ NUMBER;

    alm_exists_ NUMBER;

    XMLType count_;

    BEGIN

    IF in_id_schedule IS NULL or in_i_type_alarm_schedule IS NULL or iv_alert_type IS NULL or in_action IS NULL THEN

    raise_application_error (pk_global.not_enough_param, pk_global.not_enough_param_text);

    END IF;

    id_user_: = in_id_user;

    IF id_user_ IS NULL THEN

    id_user_: = pk_security.who_am_i;

    END IF;

    -update of configuration for the user, add / or remove

    IF in_action = 0 THEN

    -delete if this is the last of them

    XMLQuery ('SELECT count($XML/alert_types/descendant::*)'

    by passing s.x_alert_type as 'XML' content of return)

    IN count_

    OF s t_schedule_alert

    WHERE s.id_schedule = in_id_schedule

    AND s.id_user = id_user_

    and i_type_alarm_schedule = in_i_type_alarm_schedule;

    IF to_number (count_.getstringval ()) > 1 THEN

    UPDATE t_schedule_alert

    SET x_alert_type = deleteXML)

    x_alert_type,

    ' / alert_types/type [text () =' ' | iv_alert_type |] » »] »

    )

    WHERE id_schedule = in_id_schedule

    AND i_type_alarm_schedule = in_i_type_alarm_schedule

    AND id_user = id_user_;

    END IF;

    ELSIF in_action = 1 THEN

    -Add if not exists

    SELECT CASE WHEN XMLExists (' $ alert_types/XML/type [text () = $ALM]' from x_alert_type as 'XML', iv_alert_type as 'ALM')

    THEN 1 ELSE 0 END exists_

    IN alm_exists_

    OF v_schedule_alert

    WHERE id_schedule = in_id_schedule

    AND id_user = id_user_

    AND i_type_alarm_schedule = in_i_type_alarm_schedule;

    IF alm_exists_ = 0 THEN

    UPDATE t_schedule_alert

    SET x_alert_type = insertChildXML)

    x_alert_type,

    ' / alert_types', 'type ',.

    "< type >" | iv_alert_type | ' < / type > '

    )

    WHERE id_schedule = in_id_schedule

    AND id_user = id_user_

    AND i_type_alarm_schedule = in_i_type_alarm_schedule;

    END IF;

    END IF;

    RETURN THE NUMBER OF ROWS SQL %;

    END;

    As soon as I delete the sms type:

    declare

    ID_ number;

    Start

    ID_: = pk_schedule_alert.update_alert (: b1,: b2, "sms",: b3, 0);

    end;

    The select above does not return anything and the simpler query:

    Select *.

    FROM xmltable ('/ alert_types/type ')

    from (select x_alert_type in the t_schedule_alert where id_schedule =: = b1 and i_type_alarm_schedule: b2)

    "path of columns type_ varchar2 (10) ' / text()".

    ) sa;

    0 records returned.

    Although the field of XMLtype:

    "< alert_types >".

    Email from < type > < / type >

    "< / alert_types >.

    If I add more once the type of sms:

    declare

    ID_ number;

    Start

    ID_: = pk_schedule_alert.update_alert (28.2, "sms", 12034, 1);

    end;

    The main query returns 1 for sms and 0 for the event by e-mail if the xml field contains:

    "< alert_types >".

    Email from < type > < / type >

    < type > text < / type >

    "< / alert_types >.

    and the query:

    Select *.

    FROM xmltable ('/ alert_types/type ')

    from (select x_alert_type in the t_schedule_alert where id_schedule =: = b1 and i_type_alarm_schedule: b2)

    "path of columns type_ varchar2 (10) ' / text()".

    ) sa;

    reutrns 1 record, sms

    It seems that the crux of e-mail will be damaged some how by the removal of the sms you.

    If I build the XML with sms, event and email node and delete the node of sms I have sms = 0, email = 0, event = 1 even if the xml field contains:

    "< alert_types >".

    Email from < type > < / type >

    event < type > < / type >

    "< / alert_types >.

    I can't find the cause.

    Hope to be clear enough and that you can help me.

    Thanks in advance,

    Samuel

    Thanks, now I can reproduce.

    XQuery Update has the problem too:

    SQL > select id, column_value

    t_temp_xml 2,

    3 xmltable ('/ alert_types/type ' from config)

    4 where id = 1;

    ID COLUMN_VALUE

    ---------- --------------------------------------------------------------------------------

    1 sms

    1 e-mail

    SQL >

    SQL > update t_temp_xml

    2 set config = (xmlquery

    3                'copy $d := . Edit)

    4 remove the node $d/alert_types/type[.="sms"])

    5 return $from

    6 passage config

    7 content of return

    8               )

    9 where id = 1;

    1 line update

    SQL >

    SQL > select id, column_value

    t_temp_xml 2,

    3 xmltable ('/ alert_types/type ' from config)

    4 where id = 1;

    ID COLUMN_VALUE

    ---------- --------------------------------------------------------------------------------

    Still another problem with the rewrite of XQuery I guess.

    This works if you use the NO_XML_DML_REWRITE flag:

    SQL > rollback;

    Complete restoration

    SQL >

    SQL > UPDATE / * + no_xml_dml_rewrite * / t_temp_xml

    2 SET config = deleteXML (config, ' / alert_types/type [. = "sms"]')

    3 WHERE id = 1;

    1 line update

    SQL >

    SQL > select id, column_value

    t_temp_xml 2,

    3 xmltable ('/ alert_types/type ' from config)

    4 where id = 1;

    ID COLUMN_VALUE

    ---------- --------------------------------------------------------------------------------

    1 e-mail

    This should be reported to Oracle's Support.

    Maybe it's already fixed in paragraph 12.1, can't check at the moment.

  • Problem with the simple query.

    Hi all

    I am facing problem with the query below

    Select A.COL1, A.COL2

    B.COL1, B.COL2

    FROM TABLE1 A

    TABLE 1 B

    WHERE A.header = '123'

    AND B.header = '123'

    AND nvl (A.COL6, 'ABC') = 'ABC '.

    AND NVL (B.COL6, 'DEF') = 'DEF '.

    Basically, my requiremenyt is: I have only one table, TABLE1 here, which has a line two lines (for the same header) as "ABC" and another is "DEF". Table 1 has two columns (col1, col2) that should be displayed for both lines.

    When the header has two records in table1 top query works. and but if I do not have a record for any header example there are a record for "abc" in col6 only. so my query above does not work because there is no record for 'DEF' in col6. But I want to again request to fecth the output (for b.col1 and b.col2 should have null values)

    could you pls suggest me how to get the 4 columns.

    Thanks in advance

    Kind regards

    UVA.

    Try to place the status of outer join on column: analytical_criterion_code as

    and nvl (AUDIT.analytical_criterion_code, 'AUDIT2') = 'verification2. '

    .

    .

    and nvl (TRANS.analytical_criterion_code, 'TRANS2') = 'TRANS2.

    In the sub query based on the opinions that you have given in post # 1, although there is no value "DEF * ' for col6 due to the condition of outer join on b.col6 (+) line is extracted with b.col [1,2,3] as NULL values. Try to remove the (+) sign b.col6 and test.

    with t as)

    Select 111 col1, col2 'aaa', 'ABC' col6 123 header of all the double union

    Select 222 'bbb', 'DEF' col6, 123 double header

    )

    q as (select 123 double header)

    Select A.COL1, A.COL2, A.COL6

    B.COL1, B.COL2, b.COL6

    q.header

    T a

    t b

    q

    where a.col6 (+) = 'ABC '.

    and b.col6 (+) = "DEF."

    and q.header = a.header (+)

    and q.header = b.header (+)

  • problem with bind variables in the SQL query view object

    Hi all

    I use JDev 11.1.2.4.0.

    I have a problem with bind variables in the SQL query view object.

    This is my original SQL

    SELECT sum(t.TIME) , t.legertype_id
    FROM LEDGER t
    WHERE t.nctuser_id = '20022' 
          AND to_char(t.insertdate,'YYYYMMDD') in ('20130930','20130929')
    group by t.legertype_id
    

    In my view .xml object query tab, I am writing this

    SELECT sum(t.TIME) , t.legertype_id
    FROM LEDGER t
    WHERE   t.nctuser_id = '20022'
        AND to_char(t.insertdate,'YYYYMMDD') in :dddd
    group by t.legertype_id
    

    Davis here is a variable of Type liaison: String, updatable and necessary.

    I try to deal with Davis as ('20130930 ', ' 20130929') hoping the view object, run as my original SQL.

    But failed. The view object retrieves 0 line after that I run.

    Why?

    Thank you! ('2original SQL0130930', '20130929') ('20130930 ', ' 20130929')

    A variable binding cannot be used as this is why you must use years table. Check decompilation binary ADF: using oracle.jbo.domain.Array with ViewCriteria to see a solution.

    Timo

  • Problem with REGEXP_SUBSTR related query.

    I'm having a problem with this query:

    SELECT *.

    FROM (SELECT REGEXP_SUBSTR ('{SUMMER} |)) {} POINT OF SALE}',

    '({)([A-Z]+ *[A-Z]*)(})',

    1,

    LEVEL,

    'I,

    2)

    Val

    OF THE DOUBLE

    CONNECT BY LEVEL < =.

    REGEXP_COUNT ('{SUMMER} |) {} POINT OF SALE} ',' |') + 1)

    WHERE val IS NOT NULL

    I need the output in 2 rows in this format:

    VAL

    ====

    SUMMER

    POINT OF SALE

    But I'm not able to get the "POINT OF SALE" in the output due to space, or perhaps another reason. Anyone can correct my query?

    So, you want something like that?

    SQL > ed
    A written file afiedt.buf

    1. SELECT *.
    2 (SELECT REGEXP_SUBSTR ('{SUMMER} |)) {} POS} ',' [^ {|}] + ", LEVEL, 1, 'i') val"
    3 FROM TWO
    4. CONNECT BY LEVEL<>
    5 REGEXP_COUNT ('{SUMMER} |) {} POINT OF SALE} ',' [^ |] +'))
    6 * val WHERE IS NOT NULL
    SQL > /.

    VAL
    ------------------------
    SUMMER
    POINT OF SALE

    SQL >

  • Problem with the input query mode. FRM 41009, 40301

    Hi all

    I have a problem with the mode of input query. What can I say, I'm in the mode of input query, and I click on a button. I get the error THAT FRM-41009 displayed.

    Now, I've wanted handled. So I created a trigger of error in order to handle the error.

    IF ERR_CODE = 41009 THEN
    NULL;
    END IF;

    A problem is that when you use the null value, it will not terminate the mode of input query, and then I get frm-40301 error.

    Second, it's that I can't use exit_form in a trigger of the error.

    I am aware that I can press F4 to exit this mode, but I don't want to do whenever I'm sure I'll get the user complaints.

    Another solution would be to put the following code in the trigger when key pressed for each button in the form:

    If: system.mode = "ENTER-QUERY" then
    exit_form;
    end if;

    But I don't want to reproduce this code in my form.

    Please can you give me an idea how to handle this correctly?

    Thank you
    Michael

    PS: Version of the form = > ORACLE FORMS 10g (Forms [32 bit] Version 10.1.2.3.0)

    I have a problem with the mode of input query. What can I say, I'm in the mode of input query, and I click on a button. I get the error THAT FRM-41009 displayed.

    What is the code in the trigger of your button When-Button-Pressed (WBP)? Maybe you should check to see if the form is in the Mode query in your WBP rather than try and remove the error? In other words, eliminate error - do not delete it. :)

    If you want instead to remove the error, there is a technique to built-ins call restricted to a trigger that does not allow them. Do this by the use of a millisecond zero Timer. For example:

    /* Sample On-Error Trigger */
    DECLARE
      n_err_cd   NUMBER := ERROR_CODE;
      t_on_error TIMER;
      ZERO  NUMBER := 0;
    BEGIN
      IF ( n_err_cd = 41009 ) THEN
        /* Create Timer to execute Exit_Form() */
        /* to Cancel Query-Mode. */
        t_timer := Create_Timer('ON_ERROR', ZERO, NO_REPEAT);
      ELSE
        /* Handle all other errors here... */
      END IF;
    END;
    
    /* Sample When-Timer-Expired Trigger */
    DECLARE
      v_Timer  VARCHAR2(30);
    BEGIN
      v_timer := Get_Application_Property(TIMER_NAME);
    
      IF ( v_timer = 'ON_ERROR' ) THEN
        /* Notice, the timer name is case sensative! */
        Exit_Form;
      END IF;
    END; 
    

    I am aware that I can press F4 to exit this mode, but I don't want to do whenever I'm sure I'll get the user complaints.

    Well, it's just standard features of Oracle Forms. If you switch the Mode request form - you must run a query or cancel the query Mode! This is how it works. Your users need to understand that and accept it - just as they accept the functional also for other programs. ;) Another option would be to add a "Cancel request" button to your form and make it so it is enabled only when the form is placed in Query Mode. Just a thought...

    I personally prefer to prevent the occurrence of an error rather than remove the error. :)
    I hope this helps.
    Craig...

  • Problem with the help of oraext: query-database in the transformation (XSLT 2.0)

    Hello!
    I m facing a problem with the help of oraext: query-database.

    In my transformation im try the following (Simplified):
    <xsl:template match="*">
      <xsl:variable sqlQuery="select ....."/>
      <xsl:variable name="storeSec" select="oraext:query-database($sqlQuery,true(),true(),'jdbc/xref')/>               
        <xsl:choose>
         <xsl:when test="string-length($storeSec/ROWSET/ROW[1]/STORE_PART_SECTION) > 0">
              <xsl:value-of select="$storeSec/ROWSET/ROW[1]/STORE_PART_SECTION"/>
         </xsl:when>
           <xsl:otherwise>
                <xsl:value-of select"some other val"/>
           </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    {code}
    
    This always results in +some+ +other+ +val+ !!
    I´v checked the output from oraext:query-database by using getcontentAsString and if I instead test putting the expected output from oraext:queryDatabase in my variable it gives me A100 which is what i expected.
    
    {code}
    <xsl:template match="*">
      <xsl:variable sqlQuery=select ....."/>
      <xsl:variable name="storeSec">
        <ROWSET>
         <ROW num="1">
           <STORE_PART_SECTION>A100</STORE_PART_SECTION>
         </ROW>
         <ROW num="2">
           <STORE_PART_SECTION>XXm</STORE_PART_SECTION>
         </ROW>
        </ROWSET>
      </xsl:variable>               
        <xsl:choose>
         <xsl:when test="string-length($storeSec/ROWSET/ROW[1]/STORE_PART_SECTION) > 0">
              <xsl:value-of select="$storeSec/ROWSET/ROW[1]/STORE_PART_SECTION"/>
         </xsl:when>
           <xsl:otherwise>
                <xsl:value-of select"some other val"/>
           </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    How to get the correct value when you use oraext:query - database?

    How should you exit? Several item ID with each having a value of the result set?
    If Yes, then you can try following:

     
                        
                            
                        
                             
                                  
                             
                        
                            
    
  • problem with the CURSOR and WITH clause

    Hi guys,.

    I have never created a package before. I try to run it, but I get:
    ORA-06550: line 8, column 16:
    PLS-00382: expression is of the wrong type
    ORA-06550: line 8, column 3:
    PL/SQL: Statement ignored

    I know that my problem is in the next section

    OPEN FOR V_io_cursor

    with GOT_R_NUM like)


    Is the above correct?

    When I copy paste the "heart" of the query, it works very well. I really have a problem with the CURSOR and the declaration.

    Here's the code in its entirety. I know that the code is much more then he returned, but ignore this overload that was to do some tests to make sure that I can achieve any query request.

    CREATE OR REPLACE
    PKG_SPF_NATIONALREPORTS PACKAGE BODY IS

    PROCEDURE GET_NATIONAL_TOTAL_RESULTS (P_SelectFields IN varchar2, P_SUMFields IN varchar2, io_cursor IN OUT C_RESULTS)
    IS
    v_io_cursor C_RESULTS;

    BEGIN

    OPEN FOR V_io_cursor

    with GOT_R_NUM like)
    SELECT
    -START P_SelectFields
    r.cli_served,
    r.EIER,
    -END P_SelectFields
    r.RC,
    r.Year_ID,
    r.period_id,
    r.agreement_type_ind,
    CONTRACT_NUMBER. CONTRACT_NUMBER_TEXT,
    YEARS.year_desc,
    RC_CODE.rc_code_id,
    RC_CODE.rc_code,
    AHRDA HOLDERS. AHRDA_ID,
    AHRDA HOLDERS. REGION_ID,
    AHRDA HOLDERS. PROVINCE_ID,
    AGREEMENT_TYPE. AGREEMENT_TYPE_ID,
    AGREEMENT_TYPE. AGREEMENT_TYPE_DESC_EN,
    ROW_NUMBER() over (partition R.YEAR_ID, R.CONTRACT_Number_Text
    order by
    P.PERIOD_desc
    (/ / DESC NULLS LAST) AS r_num
    RESULT r
    JOIN period p ON r.period_id = p.period_id
    JOIN CONTRACT_NUMBER ON r.contract_number_text = CONTRACT_NUMBER. CONTRACT_NUMBER_TEXT
    JOIN RC_CODE ON contract_number.rc_code_id = rc_code.rc_code_id
    JOIN AHRDA holders ON ahrda.ahrda_id = rc_code.ahrda_id
    JOIN AGREEMENT_TYPE WE AHRDAS. AGREEMENT_TYPE_ID = AGREEMENT_TYPE. AGREEMENT_TYPE_id
    JOIN the YEARS WE r.year_id = YEARS.year_id
    )
    SELECT year_desc
    -START P_SUMFields
    SUM (cli_served) AS sum_cli_served
    The SUM (eier) AS sum_eier
    -END P_SUMFields
    OF got_r_num
    GROUP BY year_desc
    ORDER BY year_desc
    ;

    io_cursor: = v_io_cursor;

    END GET_NATIONAL_TOTAL_RESULTS;

    Agree - all this talk of loops FOR is completely irrelvant.
    A refcursor is usually the exact mechanism to return a result set.

    What is C_RESULTS?

    Just use SYS_REFCURSOR.

    No need for local variable.

    OUT why? Not just walk OUT?

    PROCEDURE GET_NATIONAL_TOTAL_RESULTS
    (P_SelectFields IN varchar2, P_SUMFields IN varchar2, io_cursor OUT SYS_REFCURSOR)
    IS
    BEGIN
     OPEN io_cursor FOR ...
    END;
    
  • Problem with the clause.

    I use WITH clause in one of my request... and instead to choose the table WITH I use for INSERTING records... I can do this...
    I write the quesry below and the error message... Will be great if someone can give an idea...


    WITH GADGET_MAP AS (SELECT UCP_AWU_PK, PRD_AME_PK FROM FSI_AT_USER_COUNTRY_MAPPING, FSI_AW_PROFILE_DETAILS WHERE UCP_PRF_PK = PRD_PRF_PK AND PRD_AME_PK IN (SELECT AME_PK FROM FSI_AW_MENU WHERE AME_GADGET_TYPE IS NOT NULL) LESS SELECT UGM_AWU_PK, UGM_AME_PK FROM FSI_AW_USER_GADGET_MAPPING) INSERT INTO FSI_AW_USER_GADGET_MAPPING (UGM_PK (, UGM_AWU_PK, UGM_AME_PK, UGM_GADGET_HEIGHT, UGM_GADGET_COL_ID, UGM_GADGET_ROW_ID, UGM_GADGET_MAX_ITEMS, UGM_GADGET_ANIMATION, UGM_GADGET_RELOAD_MIN, UGM_MIN_MAX_CLOSE, UGM_GADGET_TITLE, UGM_GADGET_FORM_VALUES, UGM_GADGET_DB_FILTER, UGM_GADGET_TITLE_KEY, UGM_GADGET_CREATED_BY, UGM_DELETE_ALLOWED, UGM_SHOW_MOBILE, UGM_IS_ACTIVE, UGM_MOB_SEQ, UGM_GADGET_GRAPH_TYPE) SELECT UGM_PK_SEQUENCE. NEXTVAL, UCP_AWU_PK, PRD_AME_PK, AME_GADGET_HEIGHT, AME_GADGET_COL_ID, AME_GADGET_ROW_ID, AME_GADGET_MAX_ITEMS, AME_GADGET_ANIMATION, AME_GADGET_RELOAD_MIN, 'X', AME_NAME, AME_GADGET_FORM_VALUES, AME_GADGET_DB_FILTER, AME_RESOURCE_KEY, 1, "N", "N", AME_IS_ACTIVE, AME_GADGET_MOB_SEQ, NULL FROM FSI_AW_MENU, GADGET_MAP WHERE AME_PK = PRD_AME_PK;

    Error: -.
    ERROR on line 1:
    ORA-00928: lack of SELECT keyword

    Thanks in advance...

    You must reformat the query.

    INSERT INTO FSI_AW_USER_GADGET_MAPPING
     (UGM_PK ,UGM_AWU_PK ,UGM_AME_PK ,UGM_GADGET_HEIGHT ,UGM_GADGET_COL_ID ,UGM_GADGET_ROW_ID ,UGM_GADGET_MAX_ITEMS ,UGM_GADGET_ANIMATION ,UGM_GADGET_RELOAD_MIN ,UGM_MIN_MAX_CLOSE ,UGM_GADGET_TITLE ,UGM_GADGET_FORM_VALUES ,UGM_GADGET_DB_FILTER ,UGM_GADGET_TITLE_KEY ,UGM_GADGET_CREATED_BY ,UGM_DELETE_ALLOWED ,UGM_SHOW_MOBILE ,UGM_IS_ACTIVE ,UGM_MOB_SEQ ,UGM_GADGET_GRAPH_TYPE )
    (
    SELECT UGM_PK_SEQUENCE.NEXTVAL, UCP_AWU_PK, PRD_AME_PK ,AME_GADGET_HEIGHT ,AME_GADGET_COL_ID ,AME_GADGET_ROW_ID ,AME_GADGET_MAX_ITEMS ,AME_GADGET_ANIMATION ,AME_GADGET_RELOAD_MIN ,'X' ,AME_NAME , AME_GADGET_FORM_VALUES , AME_GADGET_DB_FILTER , AME_RESOURCE_KEY ,1 ,'N' ,'N' ,AME_IS_ACTIVE , AME_GADGET_MOB_SEQ ,NULL
    FROM FSI_AW_MENU ,
    (SELECT UCP_AWU_PK, PRD_AME_PK FROM FSI_AT_USER_COUNTRY_MAPPING , FSI_AW_PROFILE_DETAILS WHERE UCP_PRF_PK = PRD_PRF_PK AND PRD_AME_PK IN
    (SELECT AME_PK FROM FSI_AW_MENU WHERE AME_GADGET_TYPE IS NOT NULL) MINUS
    SELECT UGM_AWU_PK,UGM_AME_PK FROM FSI_AW_USER_GADGET_MAPPING )  GADGET_MAP
    GADGET_MAP WHERE AME_PK = PRD_AME_PK
    );
    
  • Unique problem with selction on the table (Query Page)

    Unique problem with selction on the table (Query Page)

    I have a VO data Bulletin Board, with a transitional attribute for selction unique column.
    My requirement is that I need to identify the line that was selected in the table.

    I associated with fireAction singleSelection column, such that whenever the user selects the line
    I'm looking for that VO using some rowIterator.
    But when running the loop of the transient VO that is mapped to the singleSelection variable is the show as "n" / NUll
    for all the lines...

    So how do you identify the selected line in singleSelection to a table.

    -Sasi

    In the property inspector of the element for which you've put firePartialAction, you can find a property named "parameters". That mention primary key as your setting.

    You can get the arameter using pageContext.getparameter ();

    -Anand

  • problem with query select in the search

    Hello

    Here I use MYSQL database and when I insertind to the database date, it saves as "2009-11-10 00:00:00 ' and when I used to do this show in dateformat as November 10, 2009".

    Here's the problem occurs, when I write a search like query

    Select recruitername, interviewdate, skillset
    details
    where interviewdate = #form.interviewdate #.

    I'm not a problem with the date. could u please help me how to solve this problem.

    Or, better yet, a with a type date.

    WHERE interviewdate =

  • Problem with REPLACING the clause in Sybase

    I am facing a problem with REPLACING the clause in embedded SQL with a Sybase database.

    My Cold Fusion Server is MX 7.

    The database is the Adaptive Enterprise/12.5.0.3/EBF 10689 IR/P/Sun_svr4/OS Server 5.8/rel12503/1915/64-bit/FBO/Thu 23 Jan 16:05:19 2003

    That is the problem. I have a variable bureau_incode of Cold Fusion, which I use to set the values in my IN clause. When I comment on my request and display this value in the HTML page, bureau_incode has the following value:

    ('TAB', 'OGC', 'BIG', 'OLA', "MDG", "SEO", "OSP", "ANOTHER OWD ',' ', 'PSHSB", "CAT", "WTB")

    My CFQUERY embedded SQL looks like this:

    Quote:
    < name cfquery = "qResults" datasource = "#request.dsn #" >
    Select Name,
    bureau_code,
    Telephone,
    Mobile phone,
    Pager,
    E-mail
    Availability,
    Explanation,
    Password,
    Admin,
    last_login = convert (varchar (20), last_login, 0)
    of PAMS where availability = ' don't
    < #request.seltype # cfif IS NOT "ALL" >
    and bureau_code IN #bureau_incode #.
    < / cfif >
    < / cfquery >
  • Body of function from PL/SQL query SQL - problem with where Cluase return

    Hi all
    I have problem with sub PL/SQL. Where clause does not filter the values even when I change the value: P7_INVESTIGATOR. I have marked with an asterisk for where clause where I want the values to filtered.


    DECLARE
    v_sql varchar2 (5000);
    v_inv VARCHAR2 (100);

    Start
    v_inv: = UPPER(:P7_INVESTIGATOR);

    v_sql: = ' select TBLCASES. INVESTIGATOR as an INVESTIGATOR,';
    v_sql: = v_sql | "TBLCASES. CASENUMBER as CASENUMBER,';
    v_sql: = v_sql | "TBLCASES. OPENDATE as OPENDATE,';
    v_sql: = v_sql | "TBLCASES. ESTCOMPLETE as DATE_CIBLE,';
    v_sql: = v_sql | "TBLCASES. STATUS of STATUS ';
    v_sql: = v_sql | "TBLCASES. Case CODE case CODE as,';
    v_sql: = V_sql | "TBLCASES. FAIR_HOTLINE as FAIRHotline,';
    v_sql: = v_sql | "TBLCASES. NYSIG as NYSIGCase,';
    v_sql: = v_sql | "TBLCASES. The REGION';
    v_sql: = v_sql | "TBLCASES. PROGAREA as PROGArea ';
    v_sql: = v_sql | ' from TBLCASES where 1 = 1';
    **************************************************************
    If v_inv <>null then
    v_sql
    : = v_sql | "and UPPER (trim (tblcases.investigator)) = UPPER (trim (v_inv))';
    END IF;
    ***************************************************************
    v_sql: = v_sql | "order by tblcases.investigator";
    Return v_sql;
    end;


    Thank you

    wrote:
    Or it is possible to write it this way:

    if v_inv is not null then
    v_sql := v_sql ||'  and UPPER(trim(tblcases.investigator)) = UPPER(trim(:P7_INVESTIGATOR))';
    END IF ;
    

    In this case we will use bind variables and we all know that it is very important.

    Lev

    Of cause, it is the best option. and I strongly suggest the OP to use.
    But it depends on how the sql is used later.
    Without knowing that, we cannot be sure if the item is available here.

Maybe you are looking for