Helps with the syntax of dynamic sql statements

Hi all
How can I pass the value of the result of my dynamic select statement to a Ref Cursor?
I try the following statement but does not work, I get this error:
ORA-00932: inconsistent data types: expected - was - ORA-06512: at
Procedure getItems(v_first In number, v_second In Number, arg_Cursor IN OUT CUSTOM_REF_CURSOR) is
     sqlString varchar(3000);
     Begin
       sqlString := 'select* from bla where o.arg_1 = :1 and arg_2 = :2'; 
   
       execute immediate sqlString 
       into arg_Cursor
       using v_first, v_second;
   End getItems;
Any ideas?
Thank you

Johnny
PROCEDURE getitems (v_first IN NUMBER, v_second IN NUMBER, arg_cursor IN OUT sys_refcursor)
IS
  sqlstring   VARCHAR (3000);
BEGIN
  sqlstring := 'select* from bla where o.arg_1 = :1 and arg_2 = :2';

  OPEN arg_cursor FOR sqlstring USING v_first, v_second;
END getitems;

Tags: Database

Similar Questions

  • Help with the exception of Pl/SQL 'ora-3150 end of file on the communication channel.

    Hello.

    The code attached to this post opens a slider that load of 99 dblinks from different remote databases of different version.

    He captures the information from these databases and stores them locally on a central database (11.2.0.4.0 version) on different tables.

    The problem I have is that when a database is deleted, the dblink to this database show me the error 'ora-3150 end of file on communication channel' and that's right.

    But he's not going trough the exception that I created, the cursor is closed and does not continue with the cycle.

    The exception I created insert data on DBMONITOR error. DBMONITOR_LOG_ERROR_TABLE in order to catch the error (you'll be able to see all the code on the attachment)

    It's the exception:

    exception

    while others then

    INSERT IN DBMONITOR. DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info, FECHA_ERROR, TIPO_PROCEDURE) VALUES (var, SUBSTR (DBMS_UTILITY. (FORMAT_ERROR_STACK, 1, 200), "CONNECTION ERROR", SYSDATE, 'CAPACITY');

    commit;

    end;

    Could help me please on how could intercept this exception?

    Thank you.

    Juan.

    You might have a problem with your connection or mishandling. The end of the file ora-3150, on channel of communication error means that there is a connection, but this link was broken somehow.

    If a database is not reachable, you should get other types of errors.

    For example judgment of the Kingdom or tns - memory could not resolve alias or simliar things.

    Here is a list of typical mistakes I have check and manage when accessing remote databases.

      e_db_link_broken EXCEPTION;  --ORA-02019 connection description for remote database not found
      PRAGMA EXCEPTION_INIT (e_db_link_broken, -02019);
      e_oracle_not_available EXCEPTION;  --ORA-01034 ORACLE not available
      PRAGMA EXCEPTION_INIT (e_oracle_not_available, -01034);
      e_oracle_down EXCEPTION;  --ORA-27101: shared memory realm does not exist
      PRAGMA EXCEPTION_INIT (e_oracle_down, -27101);
      e_no_listener EXCEPTION;  --ORA-12541: TNS:no listener
      PRAGMA EXCEPTION_INIT (e_no_listener, -12541);
      e_no_service EXCEPTION;  --ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
      PRAGMA EXCEPTION_INIT (e_no_service, -12514);
      e_timeout EXCEPTION;  --ORA-12170: TNS:Connect timeout occurred
      PRAGMA EXCEPTION_INIT (e_timeout, -12170);
    

    If you have a long open session and fail to close the db links after recovered information from the remote site?

    In addition, I propose to change your dynamic insertion in a normal insert.

    First extract the data of the DB link dynamically, but just with a select statement. Then do the insertion with the result data.

    Improve your logging table to store messages up to 4000 char CHARACTER. 200 is really small for error messages.

    In addition to the DBMS_UTILITY. FORMAT_ERROR_STACK you must also connect DBMS_UTILITY. FORMAT_ERROR_BACKTRACE. Just to see if you get a better message there.

    WHEN e_db_link_broken or e_oracle_not_available or e_oracle_down or e_no_listener or e_no_service or e_timeout THEN
       INSERT INTO DBMONITOR.DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info,FECHA_ERROR,TIPO_PROCEDURE) VALUES(var, 'Remote DB not accessible','ERROR DE CONEXION',SYSDATE,'CAPACITY');
                   -- commit;
    WHEN OTHERS THEN
    
                    INSERT INTO DBMONITOR.DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info,FECHA_ERROR,TIPO_PROCEDURE) VALUES(var, SUBSTR(DBMS_UTILITY.FORMAT_ERROR_STACK||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, 1, 4000),'ERROR DE CONEXION',SYSDATE,'CAPACITY');
                    --commit;
                    end;
    
  • Zero error of iteration - the treatment of dynamic sql statements in dbms_xmlgen

    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    881575 wrote:
    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing to EXECUTE IMMEDIATE.
    COPY the statement & PASTE in sqlplus to validate its correctness.

  • Need help with the condition join in SQL

    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("Column3", 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('column4', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("column1", "table2", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column2', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', "Column3", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column4', 'varchar2')
    Commit;

    Create table all_cons_columns_test (varchar2 (30) from table_name, column_name varchar2 (30), constraint_name varchar2 (30))

    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "primary")
    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "secondary")
    Commit;

    This is my query and the current result:

    Select u.table_name, u.column_name, c.constraint_name
    Of user_tab_col_test u
    Outer join all_cons_columns_test c left
    On (u.table_name = c.table_name
    AND U.COLUMN_NAME = C.COLUMN_NAME
    AND C.CONSTRAINT_NAME IN ('main'))
    order of U.table_name, U.COLUMN_NAME;

    TABLE_NAME COLUMN_NAME, CONSTRAINT_NAME
    ------------------ --------------------- ----------------------------
    Table1 primary Column1
    Table1 Column2
    Table 1 Column3
    Table2 Column1
    Table2 Column2


    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.
    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.
    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Any advice/suggestions are appreciated-
    John

    Published by: user703358 on January 11, 2013 20:57

    Published by: user703358 on January 11, 2013 21:48

    Hi, John,.

    user703358 wrote:
    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')...

    Thanks for posting the CREATE TABLE and INSERT.
    It is more useful if you post the code that can be run without modification. You did not semicolons after INSERTION instructions.

    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.

    What have you tried? Post your best attempt.
    Here's one way:

    SELECT    u.table_name
    ,        u.column_name
    ,        c.constraint_name
    FROM             user_tab_col_test      u
    LEFT OUTER JOIN  all_cons_columns_test  c
                            ON    u.table_name     = c.table_name
                   AND   u.column_name     = c.column_name
                   AND   c.constraint_name IN ('primary')
    WHERE       u.table_name     = 'table1'          --  *****  NEW  *****
    ORDER BY  u.table_name
    ,            u.column_name
    ;
    

    You would not put this condition in the clause; who controls what is considered as a match between the tables, and "u LEFT OUTER JOIN c" means show all lines of u, even if they do not have a match in the c.

    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.

    Basically, this application is very well.
    It displays all the columns of user_tab_col_test; missing data_type. Just add u.data_type to the SELECT clause, or change the SELECT clause

    SELECT    u.*
    ,         c.constraint_name
    

    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Do you mean "" * add * one-third * column * to all_cons_columns_test '? "
    It depends on what results you want. Post new CREATE TABLE and INSERT and instructions the results you want new data.
    Most likely, the basic structure of what you've written will remain exactly the same.

  • Need help with the compilation of PL/SQL procedure

    Hi people,

    Can someone help me with the following problem?

    Version: 10g Rel 2

    I create the following proc

    CREATE OR REPLACE PROCEDURE SYS. "P_SEND_MAIL"(p_message VARCHAR2).
    is
    Start
    UTL_MAIL. SEND ('[email protected]',
    message = > 'Oracle alert. "
    subject = > p_message);
    end;
    */*

    The above proc compile successfully

    Then I create a second proc that references the above proc

    CREATE OR REPLACE PROCEDURE SYSMAN. LOG_CRITICAL_ALERTS (gravity IN MGMT_NOTIFY_SEVERITY)
    IS
    BEGIN
    -Connect all the critical severities
    IF severity.severity_code in (MGMT_GLOBAL. G_SEVERITY_CRITICAL, MGMT_GLOBAL. G_SEVERITY_CRITICAL)
    THEN
    BEGIN
    SYSMAN.p_send_mail (Severity.message);
    EXCEPTION
    WHILE OTHERS
    THEN
    -If there is that no problem, then get the notification retried
    RAISE_APPLICATION_ERROR (-20000, "Please try again");
    END;
    COMMIT;
    END IF;
    END LOG_CRITICAL_ALERTS;
    */*

    I get the following compilation error

    SYSMAN PROCEDURE. LOG_CRITICAL_ALERTS
    Online: 8
    PLS-00201: identifier ' SYSMAN. P_SEND_MAIL' must be declared

    Thanks in advance

    rogers42

    One of the basic directions using Oracle, we should NOT, do not create your own procedures user SYS (or tables also). SYS is the datadictionary. That the datadictionary is changed automatically when importing, it is never exported: provided non-Oracle of objects are ignored.
    System: essentially the same question.

    Why you have this 'problem '.
    Just because you don't read the documentation and do not want to check for errors in the online documentation.

    Would you do that, you would have known
    SYSMAN would need to execute privilege
    You have put in place a public synonym.

    --------------
    Sybrand Bakker
    Senior Oracle DBA

  • Need help with the syntax for default message.

    I want to display by default in the layout of lead for Feild "owner of lands":

    IIf (< plRegion_ITAG > = "South", "SG",
    IIf (< plRegion_ITAG > = "North", "AT",
    IIf (< plRegion_ITAG > = "East", "GK",
    IIf (< plRegion_ITAG > = "West" "BM", "Other than thesis it should be NULL")))

    ("Other than these we NULL"-> to do this, I tried a different name)

    SG, THE, BM, GK (little) are my managers society of sales/Terriotory.
    I did not miss anything, the above syntax doesnot work for me.

    Thanks in advance.

    Kind regards
    Ratan N

    Hi Ratan,

    A few notes:
    (A) you are missing a comma between "West" and "BM".
    (B) you must use "and not"
    (C) I'm not sure that you can have a drop down list remain NULL by using the IIf function. Even if you can it won't probably work with "other than these, it must be NULL.
    (D) I suggest that you actually add a value called NULL for the list of choices and after writing the syntax you can disable it to prevent your users from accidentally choose it.
    (E) should look like this:

    IIf (= 'South', 'SG',
    IIf (= 'North', 'AT',
    IIf (= 'Is', 'GK',
    IIf (= 'West', 'NULL', 'WB')))

  • Help with Javascript syntax for dynamic header / footer...

    Hello-

    I am very new to JavaScript, but I managed to frankenstein two snippets of code that work well individually, but I can't understand how to make them work together. I am applying a dynamic header and footer to a large number of documents using the batch. Here are two extracts that work, and if someone could help me to combine them, I would be very grateful!

    for (var pageNumber = 0; pageNumber < this.numPages; pageNumber ++) {var DateStamp = this.addField ("DateStamp", "text", pageNumber, [10, 15, 600, 0]);} DateStamp.textSize = 12; DateStamp.alignment = 'center'; DateStamp.textColor = color.gray; }

    this.setAction ("WillPrint", "this.getField('DateStamp').value = \"THIS DOCUMENT IS VALID FOR 24 HOURS from DATE of PRINTING:-"+ util.printd (" \"mm/dd/yyyy hh: mm tt\", new Date()) "");

    for (var pageNumber = 0; pageNumber < this.numPages; pageNumber ++) {var FilePath = this.addField ("path", "text", pageNumber, [10, 782, 600, 767]);} FilePath.textSize = 10; FilePath.alignment = "left"; FilePath.textColor = color.gray; }

    this.setAction ("WillPrint", "this.getField('FilePath').value = \"File path: \ "+ this.path");

    Thanks in advance for any help!

    The only problem is that your second order setAction is overwhelming the first. Simply combine it with a single command, as follows:

    this.setAction("WillPrint", "this.getField('DateStamp').value = \"THIS DOCUMENT IS VALID FOR 24 HOURS FROM PRINT DATE: \" + util.printd(\"mm/dd/yyyy  hh:MM tt\",new Date());  this.getField('FilePath').value = \"File Path: \" + this.path;");
    
  • help with the berries of pl sql

    Hello
    fairly new to Oracle and am not a programmer by profession.
    Trying to write a stored procedue that will create instructions to
    Insert on a bridge and are among the insert queries
    contain versions, depending on the type of column.

    so I'm a loop in a single record at a time from the dba_tab_columns.
    Basically the bottom.
    FOR the tab)
    SELECT table_name, column_name, data_type
    FROM dba_tab_columns where owner = "MY_OWNER."
    )
    LOOP
    ....
    END LOOP;
    END;

    But, what I really need to do is all columns found for loop
    each table in a table, as well as at the end of the loop foreach
    table, a line is printed on something like this:
    Insert into my_table (col1, col2,... col_last) select col1, col2...
    table@gateway_link col_last.

    The problem is in how to use the tables for each iteration of the loop to
    be stored and all printed in one line at the end of each loop
    iteration.

    I hope I'm this explaining clearly enough. It seems simple enough,
    but I am not able to understand.

    Thanks for any help.

    fwellers.

    Hello

    Here is a way to loop in the table after it is filled.
    I modified the code of Sanjay, adding a line in the DECLARE section (for all_names), commenting on the deliberate mistake and adding just about 9 lines before that the EXCEPTION section.

    declare
      TYPE typ_enames IS TABLE OF emp.ename%TYPE INDEX BY pls_integer;
      TYPE typ_emp IS TABLE OF emp%ROWTYPE INDEX BY pls_integer;
      all_names    VARCHAR2 (4000);            -- Concatenated list of employee names
      ename_table typ_enames ;
      emp_table typ_emp;
      emp_rec emp%rowtype ;
      i pls_integer ;
      cursor cur is select * from emp ;
    begin
      -- POPULATE THE ARRAY TABLE - ASSOCIATIVE ARRAY
      i := 0 ;
      open cur ;
      loop
          fetch cur into emp_rec ;
          exit when cur%notfound ;
    
          i:=i+1;
          ename_table(emp_rec.empno) := emp_rec.ename;
          emp_table(i) := emp_rec ;
      end loop ;
    
      -- USING TO GET THE NAME FROM ARRAY TABLE
      dbms_output.put_line('Emp no 7839 :'|| ename_table(7839) ) ;
      dbms_output.put_line('First record emp_table(1):'|| emp_table(1).ename ) ;
    --  dbms_output.put_line('Emp no 12345 :'|| ename_table(12345) ) ;
    
      --  LOOPING THROUGH THE ENTIRE ARRAY
      all_names := NULL;
      FOR  j  IN 1 .. i
      LOOP
          all_names := all_names || ', '
                                 || emp_table(j).ename;
      END LOOP;
      all_names := SUBSTR (all_names, 3);          -- Remove ', ' from beginning of list
      dbms_output.put_line (all_names);
    
    exception when no_data_found then
      dbms_output.put_line('Emp record not found ') ;
    end;
    /
    

    You really need not to table if everything you do is build a list as all_names. You can build the list in the same loop where you now build the table.

  • need help with the place where small sql query

    types of numbers names {}

    ID | name | ID | Phone | which | type of | ID | type |

    | 1. Jenny | 1. 867-5309 | 1. 3 | | 1. Home |
    | 4: Tom | 4: 555-1212. 3. 1 | | 4: cell |
    | 3. Smith | 3. 364-4311 | 3. 2 | | 3. work |
    | 4. Amy | 4. 936-2828 | 4. 3 | | 4. Fax |
    | 5. 525-8722 | 3. NULL | -----------
    ----------------------------

    I'm currently out put like this:

    Type name phone

    | Smith | Home | 555-1212 |
    | Smith | cell | 364-4311 |
    | Smith | NULL | 525-8722 |

    is it possible to get the time of the tree 'smith' in the name column, which confuses me a lot
    {Please can someone give idea how to solve this problem}

    Published by: user4463478 on May 20, 2009 17:38

    Edited by: user4463478 May 21, 2009 11:51

    Edited by: user4463478 May 21, 2009 11:52
    select n.name,t.type,s.phone
    from names n,numbers s,types t
    where n.id=s.who and
    s.type=t.id(+)---right outer join
    and name ='&name'
     
    

    Here go us

  • Helps with the syntax of the workflow for the custom field

    I created a custom field called 'qualified Date '. Our current workflow is at work,

    (PRE ("< SalesStage > '") <>[< SalesStage >]) AND (PRE ("< SalesStage >") = 'Lead')

    The goal is that whenever the opportunity is taken from the stage of lead, it is called.
    However, I don't want the full qualified date when a lead is moved to Closed/Lost.

    Any suggestions on how to change this workflow to make that happen.

    We have a similar workflow, and we use a slight variation of what has suggested Shilei.
    PRE ("< SalesStage > '") <>[< SalesStage >] AND PRE ("< SalesStage >") = 'Lead' AND FieldValue ("< SalesStage > '") <>' closed/lost '.

    Good luck
    Thom

  • Trace is still get generated even after disabling the option of initializing SQL statement - Custom profile

    Hi all

    We have a problem with the profile option "initialize SQL statement - Custom." We put this at the user level. After awhile, we have erased the value of the this user profile option.

    But you can still see the trace files generated are getting updated. We checked this files trc pathname returned at the bottom of the query.

    Select name, value

    the parameter $ v

    WHERE name like 'user_dump_dest;

    Please help us on how to solve this problem. We use Oracle Apps R 12.1.2 version.

    Thanks in advance

    Rambaud

    Find the trace file creation session and kill this session

    HTH
    Srini

  • Need help with the ANSI Join syntax

    Version: 11.1.0.7

    I have my select statement that returns 3000 lines and looks like
    select ..
    from tab1 a,tab2 b,tab3 c
    where a.c1=b.c1 and
    b.c2 = c.c2(+)
    and ...
    group by
    ..
    I want to convert it to ANSI SQL, because it must be able to Hibernate, and the developer says that Hibernate include only ANSI SQL. I tried something like
    select ..
    from tab1 a INNER JOIN tab2 b
    ON a.c1=b.c1 
    LEFT OUTER JOIN tab3 c
    ON b.c2=c.c2
    where ...
    group by
    ..
    I felt bad and it turned out to be the same. It returns no rows. Please help with the correct syntax.

    I'm not sure, sorry, because it's certainly the ANSI equivalent to the non-ANSI.

    Would you have examples of queries and data that you can reproduce the problem with, and that we could analyze?

    Published by: Seanmacgc on July 15, 2009 12:48

    If there is no Clause WHERE conditions in the original that are included in the ANSI version of the query in the WHERE Clause for the EXTERNAL table itself joined, then that could transform the JOIN JOIN internally, that is, all the filters on the EXTERNAL joined table should be included in the JOIN predicate - IT (b.c2 = c.2 AND c.c3 = 'X').

  • Need help with the insert statement

    Hello

    I have a question on how to write a SQL statement.

    This is the table of "base":
    CREATE TABLE TEMP_TBL
    (
    id_nr NUMBER,
    DATE_DOK DATE,
    DATE_DUE DATE,
    DATE_DOK_PAY DATE,
    DEB NUMBER,
    KRD NUMBER
    );
    
    insert into temp_tbl (ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('1',TO_DATE('11.01.2011','DD.MM.YYYY'),TO_DATE('25.02.2011','DD.MM.YYYY'),NULL,'423,24','0');
    insert into temp_tbl(ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('2',TO_DATE('16.12.2011','DD.MM.YYYY'),TO_DATE('13.06.2011','DD.MM.YYYY'),NULL,'91270,15','0');
    insert into temp_tbl(ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('3',TO_DATE('27.09.2011','DD.MM.YYYY'),TO_DATE('27.09.2011','DD.MM.YYYY'),NULL,'0','2000');
    and it comes to resoult in the target table. SQL statement must take care of the insert in a base of the target table table (example below is already provided with test data).
    create table table_sod
    (
    
          id_nr number
         ,date_from date
         ,date_to date
         ,deb_krd number
    
    );
    
    One thing to note here :  values in column deb_krd under insert 1 and 4 must be summarized in insert 4.
    
    insert into table_sod (id_nr,date_from,date_to,deb_krd) values('1',null,to_date('25.02.2011','dd.mm.yyyy'),'423,24');
    insert into table_sod(id_nr,date_from,date_to,deb_krd) values('2',to_date('26.02.2011','dd.mm.yyyy'),to_date('13.06.2011','dd.mm.yyyy'),'423,24');
    insert into table_sod(id_nr,date_from,date_to,deb_krd)values('3',null,to_date('13.06.2011','dd.mm.yyyy'),'91270,15');
    insert into table_sod(id_nr,date_from,date_to,deb_krd)values('4',to_date('14.06.2011','dd.mm.yyyy')to_date('27.09.2011','dd.mm.yyyy'),'91693,39');
    insert into table_sod(id_nr,date_from,date_to,deb_krd)values('5',null,to_date('27.09.2011','dd.mm.yyyy'),'2000');
    If someone could give me a helping hand how write correct insert statement I would be really gratefull.

    Thank you for your time!

    I came here with my own assumptions with this

    SQL> select rownum id_nr
      2       , date_from
      3       , date_to
      4       , case when date_from is null then deb
      5              else sum(case when date_from is not null then deb else 0end) over(order by id_nr, no)
      6         end deb_krd
      7    from (
      8            select id_nr
      9                 , case when lg_dt is null or ld_dt = date_due then  null else lg_dt+1 end date_from
     10                 , ld_dt date_to
     11                 , case when deb = 0 then krd else deb end deb
     12                 , no
     13              from (
     14                      select t1.*
     15                           , lead(t1.date_due) over(order by t1.id_nr, t2.no) ld_dt
     16                           , lag(t1.date_due) over(order by t1.id_nr, t2.no) lg_dt
     17                           , t2.no
     18                        from temp_tbl t1
     19                       cross
     20                       join (select 1 no from dual union all select 2 no from dual) t2
     21                       order by id_nr, no
     22                   )
     23             where ld_dt is not null
     24         )
     25  /
    
         ID_NR DATE_FROM DATE_TO      DEB_KRD
    ---------- --------- --------- ----------
             1           25-FEB-11      42324
             2 26-FEB-11 13-JUN-11      42324
             3           13-JUN-11    9127015
             4 14-JUN-11 27-SEP-11    9169339
             5           27-SEP-11       2000
     
    
  • need help with the Update statement

    Hello
    I received a question in a course and I tried my best to respond, and now my brain is giving. I would really appreciate help with the update statement. I don't mind if you do not validate a solution, a little nudge in the right direction would be really useful. I'll post that I got.

    THE QUESTION
    / * For these agents disabled on more than seven missions, change their date of deactivation of the first date of deactivation of all the agents that have been activated in the same year as the agent that you update currently.
    */

    I have it divided into parts, here is my select statement to agents disabled on more than 7 missions, which produces the deactivation_dates in the agents table that I want to update...
    SELECT
    s.deactivation_date
    FROM
    (
    SELECT
    a.deactivation_date,
    count(m.mission_id) as nomissions
    FROM
    agents a
    INNER JOIN
    missions_agents m
    on
    a.agent_id=m.agent_id
    GROUP BY
    a.deactivation_date
    ) s
    WHERE
    s.nomissions>7 AND s.deactivation_date IS NOT NULL
    .. .and the code for the first date of deactivation for each year of activation agent
    select 
    a2.deactivation_date
    from
    agents a2
    where a2.deactivation_date= 
    (
    select min(a.deactivation_date)
    from 
    agents a
    where to_number(to_char(a.activation_date,'YYYY'))=to_number(to_char(a2.activation_date,'YYYY'))
    )
    ..... I am not real to marry these two statements together in the Update statement. I can't extract each date of deactivation produced in the first select statement and their match against the first date of deactivation in the year they have been activated for the second select statement.

    Any help greatly appreciated... :))

    I began to wonder how things would :)

    user8695469 wrote:
    First of all why he chooses the date the earliest of all agents

    UPDATE  AGENTS_COPY AC /* (1) */
    SET     DEACTIVATION_DATE = (
    SELECT  MIN(AGS.DEACTIVATION_DATE)
    FROM    AGENTS_COPY  AGS
    ,       AGENTS_COPY AC /* (2) */
    WHERE   TRUNC(AGS.ACTIVATION_DATE,'YEAR') = TRUNC(AC.ACTIVATION_DATE,'YEAR') /* (3) */
    )
    

    He recovers as soon as the subquery has not been correctly set in the SET clause. It seems you are trying to update a correlated, but we are still having a conceptual shift. I have added a few comments to your code above and below will explain.

    (1): when you do a correlated update it is useful to the table alias that you did right here.

    (2): this table statement is not necessary and is the reason why the FIRST deactivation date is selected. The alias that you use (3) refers to THIS table, not the one defined in the update statement. Remove the line indicated by (2) in the FROM clause and a correlated update will happen.

    and secondly why is it to update each row, when I thought that I'm just the lines where the agents are disabled and missions > 7? Pointers on where I'm wrong would be very appreciated. (SQL = stupid query language!) :)

    user8695469 wrote: then why is it to update each row, when I thought that I'm just the lines where the agents are disabled and missions > 7? Pointers on where I'm wrong would be very appreciated. (SQL = stupid query language!) :)

    
    WHERE EXISTS
    (
    SELECT
    a.agent_id,
    count(m.mission_id)
    FROM
    agents a
    /* INNER JOIN AC ON AC.AGENT_ID = A.AGENT_ID */
    INNER JOIN
    missions_agents m
    ON
    a.agent_id=m.agent_id
    GROUP BY
    a.agent_id,
    a.deactivation_date
    HAVING
    count(m.mission_id)>7 AND a.deactivation_date IS NOT NULL
    )
    

    Once again this problem is similar to the question above that a correlation update doesn't work. Test existence of lines in an EXISTS subquery. Since your subquery is not related to the table that you are trying to update, it will be always return a line and, therefore, it returns true for EACH LINE in the AGENTS table. To limit the game to only agents > 7 missions results, you need to add a join condition that references the table in your update statement. I added one above (with comments) as a sample.

    I recommend you look over all material that you have associated with correlated subqueries, including documents that I posted above. This seems to be what you're having the problem more with. If you need me to explain the concept of correlated queries any better please let me know.

    Thank you!

  • Cannot display the results to the database during "Update": SQL statement

    Hello

    I get this error trying to update a VO via the UI or BCBrowser.

    Cannot display the results to the database during "Update": SQL statement

    This is a default single front & right THAT VO creates on the object of the entity (Database Table)

    On the same table and with the same credentials of DB, I could update the record.

    Any guess on what went wrong?

    Thanks in advance for any help.

    p.s Jdev 11.1.1.6

    Journal:

    oracle.jbo.DMLException: Houston-26041: could not publish data from database in "Update": SQL statement "START the CAR UPDATED CarEO SET SEL_ITEM =: 1 WHERE TXN_NO =: 2 AND LOGID =: AND SEQNO = 3: 4 POLL DELIVERY_MODE, CERTIFICATION_REQ, SOFT_COPY_IND, SELITEM IN: 5,: 6,: 7,: 8; END; ».

    at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:583)

    at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:8575)

    at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6816)

    at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3290)

    at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:3093)

    at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2097)

    at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2378)

    at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1615)

    at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1417)

    at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1437)

    at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2150)

    at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:740)

    at oracle.jbo.uicli.jui.JUActionBinding.actionPerformed(JUActionBinding.java:193)

    at oracle.jbo.uicli.controls.JUNavigationBar.doAction(JUNavigationBar.java:412)

    at oracle.jbo.jbotester.NavigationBar.doAction(NavigationBar.java:111)

    to oracle.jbo.uicli.controls.JUNavigationBar$ NavButton.actionPerformed (JUNavigationBar.java:118)

    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)

    in javax.swing.AbstractButton$ Handler.actionPerformed (AbstractButton.java:2318)

    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)

    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)

    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)

    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)

    at java.awt.Component.processMouseEvent(Component.java:6289)

    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)

    at java.awt.Component.processEvent(Component.java:6054)

    at java.awt.Container.processEvent(Container.java:2041)

    at java.awt.Component.dispatchEventImpl(Component.java:4652)

    at java.awt.Container.dispatchEventImpl(Container.java:2099)

    at java.awt.Component.dispatchEvent(Component.java:4482)

    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)

    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)

    at java.awt.Container.dispatchEventImpl(Container.java:2085)

    at java.awt.Window.dispatchEventImpl(Window.java:2478)

    at java.awt.Component.dispatchEvent(Component.java:4482)

    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)

    to java.awt.EventQueue.access$ 000 (EventQueue.java:85)

    in java.awt.EventQueue$ 1.run(EventQueue.java:603)

    in java.awt.EventQueue$ 1.run(EventQueue.java:601)

    at java.security.AccessController.doPrivileged (Native Method)

    in java.security.AccessControlContext$ 1.doIntersectionPrivilege(AccessControlContext.java:87)

    in java.security.AccessControlContext$ 1.doIntersectionPrivilege(AccessControlContext.java:98)

    in java.awt.EventQueue$ 2.run(EventQueue.java:617)

    in java.awt.EventQueue$ 2.run(EventQueue.java:615)

    at java.security.AccessController.doPrivileged (Native Method)

    in java.security.AccessControlContext$ 1.doIntersectionPrivilege(AccessControlContext.java:87)

    at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)

    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Caused by: java.sql.SQLException: invalid column type

    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:150)

    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:399)

    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:581)

    at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1765)

    at oracle.jbo.server.OracleSQLBuilderImpl.bindUpdateStatement(OracleSQLBuilderImpl.java:2243)

    at oracle.jbo.server.EntityImpl.bindDMLStatement(EntityImpl.java:10524)

    at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:412)

    ... 52 more

    The problem is solved now.

    new columns added to the database table, after the creation of the entity object. Those changes were not picked up in the entity object.

    I found this difference after object entity with the DB Table comparison.

    And when I added these new columns to EO & VO, I don't get this error more.

    Thanks to all who tried to help

Maybe you are looking for

  • How to activate windows on WINDOWS XP features?

    I need to turn it on so I can get the XPS Viewer running

  • AnyConnects reconnection problem.

    Hello community, I need more minds to this topic, makes me crazy! and I can't understand our reasons. 95% of the users using AnyConnect have this same problem... you open anyconnect you can connect without problems, but always after 60 sec or if VPN

  • How can smartphones blackBerry I downgrade my device software (9000 "BOLD")?

    Hello: I've recently updated my "BOLD" version of the 4.6 to 5.0 platform and is not letting me use my internet browser or anything related to the Internet like facebook and other applications. I tried to connect my phone to the Blackberry Desktop Ma

  • HRMS patches are cumulative

    Hi allI have some doubts on patches HRMS, thought to check in the community,1. the cumulative patches HRMS? as if I apply HRMS ORS 8 patch, it contains all HRMS ORS 6 updates?2 according to ML ID Oracle resources human (HRMS) pays North American annu

  • A clip ready before rolling (beginner, please excuse my bad language)

    HelloI'm a newbie, so I don't really know how to describe correctly what I would do. I make youtube videos and I have a clip at the end of the promotion of my other videos.I have a number of video tracks reduced about 15 minutes and 15 seconds. See t