Excerpt from table (insert the provided table)

I would like to get the ID with one of the specific criteria
1 iDs who ONLY have LOST STATUS and TAKEN_DTE as NULL in the YEAR 2010/2011
The ID peut have status as TAKEN previous to the YEAR 2010 but first must meet the above criteria.


CREATE TABLE CHLOE_C)
ID varchar (8),
YEAR varchar (8),
Varchar (8), the STATE
TAKEN_DTE varchar (8),
STATUS varchar (8));

INSERT ALL
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES ('80730 ","2006 ", 602" ", March 13, 2006 ', ' TAKEN')
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '80730', ' 2010 ', 705', 12 March 2010 ', "LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '6321 ', '2012', ' 1203', 13 March 2012 ', ' LOST')
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '6321 ', '2012', ' 1209', 13 March 2012 ', ' TAKEN')
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES ('75454 ', '2010', ' 1015', ","LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '75454', ' 2011 ', 602', March 13, 2011 ', ' TAKEN')
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES ('100 ', '2010', 6102', ","LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '100 ', '2009', 6152', March 13, 2009 ', ' TAKEN')
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '100', ' 2006 ', 61152', March 13, 2006 ', ' LOST')
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES ('99 ', '2009', 5402', ","LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '99 ', '2010', 6102', 13 March 2010 ', "LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES ('88 ', '2011', 6102', ","LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES ('88 ', '2010', 6102', ","LOST")
IN chloe_c (ID, YEAR, STATE, TAKEN_DTE, STATUS) VALUES (' '88 ', '2009', 6102', 13 March 2010 ', "TAKEN")
SELECT * FROM dual;

THEN
ID 88 YES because it saisfies the criteria it has NULL in TAKEN_DTE and STATUS as LOST, for the two years
99 NO ID that she satisfied the STATE but it has a TAKEN_DTE year 2010
ID 100 YES it has the STATUS as LOST and YEAR 2010 (STATUS TAKEN is prior 2010 so its ok)
ID 6321 NO YEAR IS 2012 (DO YOU WANT ANYTHING FROM 2012)
75454 ID number STATE is LOST for 2010 which is what we want, but she also TOOK in 2011 which we do not want
80730 NO ID even if the STATUS is LOST TAKEN_DTE is not NULL
ID 
88
100
I tried something like this:
Select distinct C.ID
FROM chloe_c C
WHERE  c.taken_dte IS NULL
AND YEAR in ('2010','2011')
AND ID not in (SELECT ID FROM chloe_c c WHERE c.status = 'Taken' and c.year in ('2011','2010'))
but it also gives me ID 75454

Hello

That's what you asked for:

SELECT    id
FROM       chloe_c
WHERE       year          IN ('2010', '2011')
GROUP BY  id
HAVING       COUNT ( CASE
                  WHEN  status     = 'LOST'
                AND   taken_dte     IS NULL
                THEN  'OK'
              END
          ) = COUNT (*)
;

Thnaks for the display of the sample data. don't forget why do you: that people who want to help you can recreate the problem and test their ideas. If you post code that does not work, then it is not so useful. You try to put 11 strings, for example, March 13, 2006 ", in a column of type VARCHAR (8)" Test your code before you post.
Use VARCHAR2, VARCHAR not, for strings.
Use DATE (or perhaps TIMESTAMP), no strings to the date information.

Tags: Database

Similar Questions

  • Automatic excerpt from Table

    It's about automating excerpt. I want to create sql/plsql and automation of the extract of a table. For argument sake tell I 356000 lines in the table. I want to copy the snippet and paste it to Excel and as you know excel 2003
    cannot have a 65536 rows limit. If I could copy and paste the first 50000 lines in the first tab of the worksheet "sheet1" to excel and then lines 50000 on the next "Sheet2" and so on until the last fire 56000 rows of data stuck on the "sheet7.

    If you could guide me please how I do to create the sql or pl/sql to automate this task. Also I mine if it is semi-automated for example. creation of sql/plsql to create a snippet for the first $ 50,000 lines and side lines 50001 to 100,000 and so thus until the end. And I would like to copy and paste in excel manually.

    See you soon
    Ricard

    Published by: user531731 on 03/23/2010 17:21

    Published by: user531731 on 03/23/2010 17:41

    You probably want to use the heart of which is the link Pierre gave

    Or you can use a package that does exactly that and more
    https://XML-spreadsheet.SampleCode.Oracle.com
    You can pass a query to xml_spreadsheet.abfrage and it will generate a new worksheet after 64000 lines by default. You can customize this setting.

    Concerning
    Marcus

  • Lightroom 5: excerpts from performance, but the boxes are not available for import in fact

    Help! I took a bunch of pictures last night and that they import into LR. I've been using this same camera (5dIII) and installation of LR (version 5.0, camera RAW 8.0) for more than a year.


    I tried to cope with the files on the hard disk through picture Capture and then import from the finder. Image capture has been fine with it, but they will not yet import into LR.


    Saw her look fine, but gray and no check box. (see photo).


    When I go to the finder and arrow through them, funky look previews. (see another photo).


    Previews happening as well in the Image Capture. Any thoughts?


    Screen Shot 2015-07-10 at 6.16.25 AM.png

    Screen Shot 2015-07-10 at 6.17.12 AM.png

    When images are displayed like this in the import dialog box, it is usually an indication that they are already in the catalog. If you are sure that these images are not in the catalogue, it is possible that the camera has started on in its file naming process for now you have more images with the same file name?

  • Excerpt from time in the data type Date

    Hi guys,.

    I run the query below:
     
    select to_char(sysdate,'hh24:mi:ss') from dual 
    14:39:04
    
    select to_date(to_char(sysdate,'hh24:mi:ss'),'hh24:mi:ss') from dual
    01/07/2012 14:39:40
    Is is possible to get just the part time in IE the date in any case data type, using the second request, I should get only the part time instead of any date and time.

    See you soon,.
    Shaz

    Hi, Shaz,

    SH * wrote:
    Is is possible to get just the part time in IE the date in any case data type, using the second request, I should get only the part time instead of any date and time.

    Lol DATEs in Oracle always include year, month, day, hours, minutes, and seconds. There is no way to get a DATE without each of them.

    You may want to store this data in an INTERVAL column, not a DATE.
    Depending on how you plan to use, a NUMBER might work, too (for example, the number of minutes after midnight) or a VARCHAR2, such as ' 09: 53:32'.
    If you really need to use a DATE for any reason, you may simply ignore the year, month and day or put always a default value, such as 1 January 0001.

    What is the problem you're trying to solve? If you explain what you need to do, then someone can help you find a good way to do it.

  • How to insert image from mysql into the table using php and create the checkbox in the table?

    How can I insert image from mysql into the table using php and create the checkbox for each data as a vote? Here is my code...

    WELCOME

    connect_error) {die ("connection failed:".)} $conn-> connect_error); } $sql = "SELECT no, Calon, ID, of course, the Image OF THE candidates." $result = $conn-> Query; If ($resultat-> num_rows > 0) {echo ' '; export data of each line while ($row = $result-> fetch_assoc()) {"echo"}}
    NO Candidate INFO Vote
    " . $row ["no"]. "-" . $row ["Calon"]. "
    -" . $row ['ID']. "
    -" . $row ['class']. "
    "; } ECHO ' ' ;} else {echo '0 results' ;} $conn-> close();?} >

    hope someone can help me because I am a newbie in this program... need to finish this project... Thank you.

    If you have saved the file name in the database, it's pretty simple.

    echo '' . $row['description'] . '';
    

    Is the same for the box:

    echo '';
    

    If you have saved the image file in the database, it is much more complicated. I recommend you store only the file name in the database.

  • How can I get a name of table 1, column A, if column B is a negative number and insert the names of table 2?

    How can I get a name of table 1, column A, if column B is a negative number and insert the names of table 2?

    What is the formula?

    You can do this with a column of "index" in table 1, as this assistance:

    The formula in C2, filled to the bottom:

    IF (B =<>

    That increments a counter each time that it finds a negative number in column B.

    In the second table, you can retrieve a list of negative values in this way:

    The formula in A2, filled to the bottom:

    = INDEX (array 1::A, CORRESPONDENCE (LINE (−1, Table 1::C), 0))

    It takes the line number, the formula is activated, subtracts 1 to the header line and look up the result in the column of table 1 C.  If it finds a match, it feeds the line number to the INDEX page with retrieves the value of the column of table 1A.

    To hide the red triangles of signage wrap the IFERROR formula, like this:

    = SIERREUR (INDEX (table 1::A, CORRESPONDENCE (LINE (−1, Table 1::C), 0)),"")

    Of course, you can also simply filter on column B without the need to set up a column from another table or index.

    SG

  • Insert the ring into table

    Dear all,

    Is it possible to insert the ring into Table?

    I have a Table whose values are constant, but not fixed, for example, Col 1 can be set to 1 or 2.

    I am attaching the picture of the table to show clearly what I want.

    Collar "Site" can have values On or OFF.

    Nervous collar can have the values 1, 2 or 3.

    Col. Ampl can have values from Ridge to Ridge or Bs - PK.

    Is it possible to make a table to store multiple values for a cell?

    Thank you

    Ritesh

    Hi Mickaël

    This link will give you full details about your query. If it works let me know.

    http://forums.lavag.org/table-with-drop-down-items-t11249.html

  • How to use several adf 12 shape and insert the form data in to table during the click on "submit" button

    How to use several adf 12 shape and insert the form data in to table during the click on "submit" button. Can we use several form from adf or not?

    Make sure that you dragged the VO based EO.

    Also make sure that the VO attributes based EO Updatable property.

    The query according to VO is used only to add LOV to the column of the original VO ModelId.

    See you soon

    AJ

  • How to insert the output in the Oracle database table records

    Nice day

    I have two tables (table A and table B) in my oracle database I created a process for mapping from Table A duplicate records to Table B, and the result (reports) must be inserted into the Table B. I can't make this process. Can someone help me please.

    Thank you and best regards,

    Muhammed Faraz

    Hi Muhammed,

    You will need create an export job and set up a new job as a result. Take a look in the help topic "export data" as he will explain the different options [Add/Remove and insert/etc.].

    Thank you

    Nick

  • Insert into MDQ_OLD select * from table (lt_monitorMdq);

    I'm trying to insert into a table that has only a single column, which is a column of a user defined type (UDT). The UDT is nested, that is one of the attributes of the UDT is an another UDT.

    I aim to insert into the table like this pseudo-code:

    INSERT INTO T1 SELECT * FROM THE UDT;

    CREATE TABLE MDQ_OLD (myMDQ UDT_T_MONITOR_MDQ)

    NESTED TABLE myMDQ

    (T1_NEW) ACE STORE

    THE NESTED TABLE MONITOR_MDQ_PRIM_RIGHTS

    STORE AS T2_NEW);

    The MONITOR_MDQ_CLI procedure. Read below returns the parameter lt_monitorMdq which is a UDT type as announced. The statement "insert into select MDQ_OLD * table (lt_monitorMdq);" fails, while the second insert statement works.

    Is it possible to get the first statement of work?

    I'm on Oracle 11 g 2.

    DECLARE

    lt_monitorMdq UDT_T_MONITOR_MDQ;

    BEGIN

    MONITOR_MDQ_CLI. Reading (TRUNC (SYSDATE),

    TRUNC (SYSDATE),

    NULL,

    NULL,

    "MILLION BTU.

    lt_monitorMdq); -Note lt_monitorMdq is an OUT parameter

    -This insert does not work

    Insert into MDQ_OLD select * from table (lt_monitorMdq);

    BECAUSE me in 1... lt_monitorMdq.count

    LOOP

    Dbms_output.put_line ('lt_monitorMdq: ' | .mdq_id lt_monitorMdq (i));

    -This integration works

    INSERT INTO MDQ_OLD (MYMDQ)

    VALUES (UDT_T_MONITOR_MDQ (UDT_R_MONITOR_MDQ)

    lt_monitorMdq (i) .gasday,

    1,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    () UDT_T_MONITOR_MDQ_PRIM_RIGHT

    () UDT_R_MONITOR_MDQ_PRIM_RIGHT

    1,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    (NULL)));

    END LOOP;

    END;

    have you tried:

    INSERT INTO MDQ_OLD (myMDQ) VALUES (lt_MonditorMDq);

    curiosity:

    Is there a particular reason, why you have created a table with a single column of type UDT instead of:

    CREATE TABLE... OF UDT_T_MONITOR_MDQ;

    I can tell you from experience that using a nested table, you can easily query the data in the nested table.

    MK

  • Insert the ROWNUM in a column of data type of NUMBER table

    Hello

    I have a table that has a column named "rank" of the NUMBER data type. Basically, I want to make an analysis of top-n and insert the ROWNUM with other columns in the table.

    Definition of table1:

    CREATE TABLE

    (

    col1 VARCHAR2 (10),

    Col2 NUMBER,

    NUMBER of col3,

    rank NUMBER

    );

    INSERT INTO table1

    SELECT col1, col2, col3, rownum

    DE)

    SELECT col1, col2, col3

    FROM table2

    ORDER BY DESC of col3

    )

    WHERE rownum < = 5;

    I get an error ORA-01722: invalid number. I think the mistake is virtual ROWNUM is not data type of NUMBER, so I tried to cast as CAST (ROWNUM AS NUMBER), but it does not work, same error. Can can you please shed some light on how to convert a ROWNUM number or if the issue is something else.

    you're right, your example worked. It is an example of table I just created just to illustrate the problem, but my real table was always showing the same problem. Weird, isn't? However when I added the column names after that insert the question but statement I resolved. Adding code

    INSERT INTO TABLE1

    (col1, col2, col3, rank) - added

    SELECT col1, col2, col3, rownum

    DE)

    SELECT col1, col2, col3

    FROM table2

    ORDER BY DESC of col3

    )

    WHERE rownum<=>

    So that means ROWNUM returns number; and another confusion: why the inclusion of the column has solved my problem when it is not necessary for your example. in any case thank you.

  • Insert the data in the table another table

    Hi experts,

    I am currently using the version below:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production           
    PL/SQL Release 11.2.0.1.0 - Production                                           
    CORE     11.2.0.1.0     Production                                                         
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production                          
    NLSRTL Version 11.2.0.1.0 - Production                                           
    My requirement is to insert a table of data in the other table.

    Table 1:
    create table a (a1 number);
    
    insert into a values (1);
    insert into a values (null);
    insert into a values (3);
    Table 2:
    CREATE TABLE c (b1 number not null);
    
    
    Note : table c have b1 column with not null constraint
    I wrote the code to insert the lines below.
     declare 
    v_a1 a.a1%TYPE;
    CURSOR c1 IS SELECT a1 FROM a;
    BEGIN
    OPEN c1;
    for i in 1..3 loop
    FETCH c1 INTO v_a1;
    EXIT WHEN c1%notfound;
    INSERT INTO c values(v_a1);
    commit;
    end loop;
    close c1;
    end;
    He insert 1 row, then after I get the error message like: 01400. 00000 - "impossible to insert a NULL value in (%s)."


    But I want the output as:
    SELECT * FROM c;
    
    OUTPUT :
    1
    3
    Please give the solution to the prescription above.


    Thank you

    I think you are looking for DML ERROR LOGGING

    SQL> desc a_tab
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ------------------------------------
     COL1                                                           NUMBER
     COL2                                                           NUMBER
     COL3                                                           NUMBER
     COL4                                                           NUMBER
    
    SQL> desc b_tab
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ------------------------------------
     COL1                                                  NOT NULL NUMBER
     COL2                                                  NOT NULL NUMBER
     COL3                                                           NUMBER
     COL4                                                           NUMBER
    
    SQL> execute dbms_errlog.create_error_log('b_tab', 'b_tab_err')
    
    PL/SQL procedure successfully completed.
    
    SQL> desc b_tab_err
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ------------------------------------
     ORA_ERR_NUMBER$                                                NUMBER
     ORA_ERR_MESG$                                                  VARCHAR2(2000)
     ORA_ERR_ROWID$                                                 ROWID
     ORA_ERR_OPTYP$                                                 VARCHAR2(2)
     ORA_ERR_TAG$                                                   VARCHAR2(2000)
     COL1                                                           VARCHAR2(4000)
     COL2                                                           VARCHAR2(4000)
     COL3                                                           VARCHAR2(4000)
     COL4                                                           VARCHAR2(4000)
    
    SQL> insert into b_tab(col1, col2, col3, col4)
      2  select col1, col2, col3, col4
      3    from a_tab
      4  log errors into b_tab_err('my_test') reject limit unlimited;
    
    2 rows created.
    
    SQL> select * from b_tab;
    
          COL1       COL2       COL3       COL4
    ---------- ---------- ---------- ----------
             1          2          3          4
             6          8          4          9
    
    SQL> set serveroutput on
    SQL>
    SQL> exec dev_util.print_table('select * from b_tab_err')
    
    -------------------------------------------------------
    Field Name                      Field Value
    -------------------------------------------------------
    ORA_ERR_NUMBER$               : 1400
    ORA_ERR_MESG$                 : ORA-01400: cannot insert NULL into("ARBORU"."B_TAB"."COL2")
    ORA_ERR_ROWID$                :
    ORA_ERR_OPTYP$                : I
    ORA_ERR_TAG$                  : my_test
    COL1                          : 5
    COL2                          :
    COL3                          : 3
    COL4                          : 6
    -------------------------------------------------------
    Field Name                      Field Value
    -------------------------------------------------------
    ORA_ERR_NUMBER$               : 1
    ORA_ERR_MESG$                 : ORA-00001: unique constraint(ARBORU.SYS_C00658187) violated
    ORA_ERR_ROWID$                :
    ORA_ERR_OPTYP$                : I
    ORA_ERR_TAG$                  : my_test
    COL1                          : 1
    COL2                          : 9
    COL3                          : 9
    COL4                          : 0
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Insert the problem using a SELECT table with an index by TRUNC function

    I came across this problem when you try to insert a select query, select returns the correct results, but when you try to insert the results into a table, the results are different. I found a work around by forcing a selection order, but surely this is a bug in Oracle as how the value of select statements may differ from the insert?

    Platform: Windows Server 2008 R2
    11.2.3 Oracle Enterprise Edition
    (I've not tried to reproduce this on other versions)

    Here are the scripts to create the two tables and the data source:
    CREATE TABLE source_data
    (
      ID                 NUMBER(2),
      COUNT_DATE       DATE
    );
    
    CREATE INDEX IN_SOURCE_DATA ON SOURCE_DATA (TRUNC(count_date, 'MM'));
    
    INSERT INTO source_data VALUES (1, TO_DATE('20120101', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120102', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120103', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120201', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120202', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120203', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120301', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120302', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120303', 'YYYYMMDD'));
    
    CREATE TABLE result_data
    (
      ID                 NUMBER(2),
      COUNT_DATE       DATE
    );
    Now, execute the select statement:
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM')
    You should get the following:
    1     2012/02/01
    1     2012/03/01
    1     2012/01/01
    Now insert in the table of results:
    INSERT INTO result_data
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM');
    Select the table, and you get:
    1     2012/03/01
    1     2012/03/01
    1     2012/03/01
    The most recent month is repeated for each line.

    Truncate your table and insert the following statement and results should now be correct:
    INSERT INTO result_data
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM')
    ORDER BY 1, 2;
    If someone has encountered this problem before, could you please let me know, I don't see what I make a mistake because the selection results are correct, they should not be different from what is being inserted.

    Published by: user11285442 on May 13, 2013 05:16

    Published by: user11285442 on May 13, 2013 06:15

    Most likely a bug in 11.2.0.3. I can reproduce on Red Hat Linux and AIX.

    You can perform a search on MOS to see if this is a known bug (very likely), if not then you have a pretty simple test box to open a SR with.

    John

  • Insert the output of a refcursor procedure into a table

    Hello

    I met a scenario in which I need to put the insert records returned by a procedure using refcursor, at a table.

    I followed the instructions in PL/SQL 101: understanding Refcursor (PL/SQL 101: understanding Ref Cursor am unfortunately still not able to do so.)

    Here is my sample codes. (Copied here as advised by the new Member)
    create or replace PROCEDURE TEST_PROCEDURE1 ( p_cursor OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT C1,C2
    FROM TEST_USER.test_table4procedure;
    END;
    I check the result using the following statement, which gives results.
    variable rc refcursor;
    exec TEST_USER.TEST_PROCEDURE1 (:rc)
    print rc;
    Now, I want to be able to use the output and insert the data into a table. That's how I came across this thread.

    I created the types and function...
    create or replace type test_user.type_table1 as object(var1 varchar2(50),var2 varchar2(50));
    create or replace type test_user.type_table2 as table of test_user.type_table1;
    
    create or replace function test_user.test_function1 (rc in sys_refcursor )
    return test_user.type_table2 is
    v_emptype test_user.type_table2 := test_user.type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_rc sys_refcursor;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    v_rc := rc;
    loop
    fetch v_rc into v_var1, v_var2;
    exit when v_rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := test_user.type_table1(v_var1, v_var2);
    end loop;
    close v_rc;
    return v_emptype;
    end;
    After that, I want to be able to view the records by using the function... so I used the instructions below...
    variable rc refcursor;
    exec TEST_USER.TEST_PROCEDURE1 (:rc)
    SELECT * FROM TABLE(test_user.test_function1(:rc));   
    However, it fails with the error

    Error from line 3 in order:
    SELECT * FROM TABLE (test_user.test_function1 (:rc))
    Error report:
    SQL error: Missing a setting IN or OUT to index: 1

    Help, please...

    Your code does not work for a simple reason. SYS_REFCURSOR parameters must be in IN OUT mode. Check if the RC is open when he switched mode:

    create or replace type type_table1 as object(var1 varchar2(50),var2 varchar2(50))
    /
    create or replace type type_table2 as table of type_table1
    /
    create or replace PROCEDURE TEST_PROCEDURE1 (p_cursor IN OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT ENAME,JOB FROM EMP;
    END;
    /
    create or replace function test_function1 (rc in sys_refcursor )
    return type_table2 is
    v_emptype type_table2 := type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    if rc%isopen
      then
        dbms_output.put_line('rc is open');
      else
        dbms_output.put_line('rc is not open');
     end if;
    loop
    fetch rc into v_var1, v_var2;
    exit when rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := type_table1(v_var1, v_var2);
    end loop;
    close rc;
    return v_emptype;
    end;
    /
    variable rc refcursor
    exec TEST_PROCEDURE1(:rc)
    set serveroutput on
    SELECT * FROM TABLE(test_function1(:rc))
    /
    SELECT * FROM TABLE(test_function1(:rc))
                        *
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at "SCOTT.TEST_FUNCTION1", line 15
    
    rc is not open
    SQL> 
    

    Now IN OUT parameter edit mode:

    set serveroutput off
    create or replace function test_function1 (rc in out sys_refcursor )
    return type_table2 is
    v_emptype type_table2 := type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    if rc%isopen
      then
        dbms_output.put_line('rc is open');
      else
        dbms_output.put_line('rc is not open');
     end if;
    loop
    fetch rc into v_var1, v_var2;
    exit when rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := type_table1(v_var1, v_var2);
    end loop;
    close rc;
    return v_emptype;
    end;
    /
    variable rc refcursor
    exec TEST_PROCEDURE1(:rc)
    set serveroutput on
    declare
    v_emptype type_table2 := type_table2();
    begin
    v_emptype := test_function1(:rc);
    end;
    /
    rc is open
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    Problem is that you can't call the procedure/function with parameters in/out OUT of SQL.

    SY.

  • Doubt by inserting the Date and time in the table

    Hi I created a table with two columns "Order_ID" and "Order_date" as

    create table test
    (
    whole order_id,
    ORDER_DATE date default sysdate
    );

    Now, I insert a line in the
    insert into test (order_id) values (1);

    now, I get the result as
    ORDER_ID ORDER_DAT
    ------------- --------------
    1 JUNE 5, 12

    But I need to insert the time current system also in the Order_date column.
    How can I achieve this?

    It works well for me!

    bcm@bcm-laptop:~$ sqlplus user2/user2
    
    SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 4 20:19:57 2012
    
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    20:19:58 SQL> @test1
    20:20:01 SQL> create table test1
    20:20:01   2  (
    20:20:01   3  order_id integer,
    20:20:01   4  order_date date default sysdate
    20:20:01   5  );
    
    Table created.
    
    20:20:01 SQL>
    20:20:01 SQL> insert into test1(order_id) values(1);
    
    1 row created.
    
    20:20:01 SQL> select * from test1;
    
      ORDER_ID ORDER_DATE
    ---------- -------------------
          1 2012-06-04 20:20:01
    
    20:20:01 SQL> 
    

Maybe you are looking for