How to use a collection type of variable binding to execute dynamic statement

Hello

We have a case where we copy selective data from A to B schema of schema in an oracle database. The copy is obtained using
run immediately 'insert'. target_schema |'. TableA select * from '. from_schema |'. where a.id table (select test_id of ' | from_schema |'.) Table c); " ;

It works very well it takes an average of 10 seconds to copy around 14 paintings. We have an obligation to bring this time to 2 seconds. An observation was the clause
"Select test_id of ' | '. from_schema |'. Table c"in the statement sql preceding repeats for many inserts. So, we thought bulk get this set of codes of practice and use a vatiable bind to collection for the immediate run clause type. Any suggestions on how to achieve this?

Thank you
Chauvin

>
in fact, you cannot use native liaison as table_names in dynamic sql variable.
>
True - but OP uses a query string and can factor that string to do what was wanted
>
So we thought bulk get this set of codes of practice and use a collection type bind vatiable
>
It works

CREATE OR REPLACE Package PK_BULK as
    Type code_tab_type is table of varchar2(25) index by varchar2(25);
    Type code_list_type is table of varchar2(25);
    FUNCTION  SF_LOAD_CODE_TAB (TAB_NAME IN VARCHAR2, COL_NAME IN VARCHAR2) RETURN CODE_TAB_TYPE;
End PK_BULK;
/

CREATE OR REPLACE Package BODY PK_BULK as
    FUNCTION  SF_LOAD_CODE_TAB (TAB_NAME IN VARCHAR2, COL_NAME IN VARCHAR2) RETURN CODE_TAB_TYPE is
    query VARCHAR2(100);
    code_tab CODE_TAB_TYPE;
    code_list code_list_type;
Begin
    query := 'SELECT ' || COL_NAME || ' FROM ' || TAB_NAME;
    EXECUTE IMMEDIATE query BULK COLLECT INTO code_list;
    FOR i IN code_list.FIRST .. code_list.LAST LOOP
       code_tab(code_list(i))  := code_list(i);
    END LOOP;
    RETURN code_tab;
End;
End PK_BULK;
/

-- test it
declare
  i VARCHAR2(25);
  code_tab PK_BULK.CODE_TAB_TYPE;
  BEGIN
    CODE_TAB := pk_bulk.sf_load_code_tab ('emp', 'ename');
    i := code_tab.first;
    while i is not null loop
      DBMS_OUTPUT.PUT_LINE (code_tab(i));
       i := code_tab.next(i);
    end loop;
  END;
 

Tags: Database

Similar Questions

  • Data Modeler: how to create and use the collection type

    Hello
    essentially of departure I don't understand how (for example) create and use the data based on the type of data varray type.

    Please notify.
    Thank you
    Andrew

    Hi André,.

    You can create new types of collection (varray/table) in two ways:
    (1) in the browser - find 'Types of data' > 'Types of Collection' node menu dropdown - there just 'create new collection type' it
    (2) in the types of data model diagram - you can create collection "some type structured" or collection of references to the it - use 'new Collection... '. "tool and click first on sight structured type and after the structured type that will contain the collection - new attribute is added to the latter and if there is none this type of collection already didn't set the new collection type are created and you can change it later.

    Philippe

  • How to use Bulk collect in dynamic SQL with the example below:

    My Question is

    Using of dynamic SQL with collection in bulkif we pass the name of the table as "to the parameter' function, I want to display those

    An array of column names without vowels (replace the vowels by spaces or remove vowels and display).

    Please explain for example.

    Thank you!!

    It's just a predefined type

    SQL> desc sys.OdciVarchar2List
     sys.OdciVarchar2List VARRAY(32767) OF VARCHAR2(4000)
    

    You can just as easily declare your own collection type (and you are probably better served declaring your own type of readability if nothing else)

    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE
      2     PROCEDURE TBL_COLS_NO_VOWELS(
      3                                  p_owner VARCHAR2,
      4                                  p_tbl   VARCHAR2
      5                                 )
      6  IS
      7     TYPE vc2_tbl IS TABLE OF varchar2(4000);
      8     v_col_list vc2_tbl ;
      9  BEGIN
     10      EXECUTE IMMEDIATE 'SELECT COLUMN_NAME FROM DBA_TAB_COLUMNS WHERE OWNER = :1 AND TABLE_NAME = :2 ORDER BY COLUMN_ID'
     11         BULK COLLECT
     12         INTO v_col_list
     13        USING p_owner,
     14              p_tbl;
     15      FOR v_i IN 1..v_col_list.COUNT LOOP
     16        DBMS_OUTPUT.PUT_LINE(TRANSLATE(v_col_list(v_i),'1AEIOU','1'));
     17      END LOOP;
     18*  END;
    SQL> /
    
    Procedure created.
    
    SQL> exec tbl_cols_no_vowels( 'SCOTT', 'EMP' );
    MPN
    NM
    JB
    MGR
    HRDT
    SL
    CMM
    DPTN
    
    PL/SQL procedure successfully completed.
    

    Justin

  • How to use the number as a variable?

    Hello

    I use SQL Developer 4.1.0.19.07... and every time I have use something like...

    variable myVar Number;
    execute :myVar := 10;
    

    A query as...

    select :myVar "myVar" from dual;
    

    Give me the output...

    myVar
    -----
          -- that is "null", as I don't have a null replacement ;-)
    

    What I am doing wrong? Any advice (in addition to using VarChar2)?

    Thanks in advance

    Peter

    This seems to be the same bug as noted in a discussion earlier: print in SQL Developer 4.1

  • collection as a variable binding

    Hello

    I created the following procedure, which works very well. However, when I want to replace the BEGIN END block of isnide with the EXECUTE IMMEDIATE statement commented, he starts throwing errors like:

    ORA 01006: bind value does not exist,
    ORA 01008: too many values to bind,
    ORA 06531: refers to a collection of uninitialized,

    No matter how I try to change the code. Note that bind variable: 3 and: 4 are collections and link the variable: 3 is a called in IN OUT mode. I read that I can use collections as bind values and now his. Someone has encountered similar problems before? Any help would be appreciated. Thank you!
    PROCEDURE TESZT002_DUP_ELLENORIZ AS
    CURSOR C1 IS (
      SELECT OBJ_TESZT002_ID(TO_CHAR(DATUM,'J')||TO_CHAR(SOR))
      FROM TESZT002 
      GROUP BY TO_CHAR(DATUM,'J')||TO_CHAR(SOR) 
      HAVING COUNT(*)>1
      );
    TESZT002_AZONOSITO VAR_TESZT002_ID;
    TESZT002_TABLA VAR_TESZT002;
    
    COUNTER NUMBER(38);
    LIMIT_SIZE NUMBER(38);
    C1_ROWCOUNT NUMBER(38);
    VALTOZO_ELEMZO VAR_VALTOZO_ELEMZO:=VAR_VALTOZO_ELEMZO();
    COLNAME VARCHAR2(30);
    I NUMBER(38);
    J NUMBER(38);
    BEGIN
    
    OPEN C1;
    SELECT COUNT(*) INTO C1_ROWCOUNT FROM (
      SELECT TO_CHAR(DATUM,'J')||TO_CHAR(SOR) 
      FROM TESZT002 
      GROUP BY TO_CHAR(DATUM,'J')||TO_CHAR(SOR) 
      HAVING COUNT(*)>1);
      
    COUNTER:=0;
    LIMIT_SIZE:=1000;
    
    COLNAME:='ERTEK1';
    LOOP
      FETCH C1 BULK COLLECT INTO TESZT002_AZONOSITO LIMIT LIMIT_SIZE;
      EXIT WHEN C1_ROWCOUNT<=COUNTER;
      COUNTER:=COUNTER+LIMIT_SIZE;
      
      SELECT OBJ_TESZT002(BS.DATUM,BS.SOR,BS.BETOLT_DATUM,BS.ERTEK1,BS.ERTEK2,BS.ERTEK3) BULK COLLECT INTO TESZT002_TABLA FROM TESZT002 BS, TABLE(TESZT002_AZONOSITO) A
      WHERE TO_CHAR(BS.DATUM,'J')||TO_CHAR(BS.SOR)=A.AZONOSITO
      ORDER BY TO_CHAR(BS.DATUM,'J')||TO_CHAR(BS.SOR);
      
      I:=TESZT002_AZONOSITO.FIRST;
      WHILE I<=TESZT002_AZONOSITO.LAST
      LOOP
        J:=I;
        WHILE TO_CHAR(TESZT002_TABLA(I).DATUM,'J')||TO_CHAR(TESZT002_TABLA(I).SOR)=TO_CHAR(TESZT002_TABLA(J).DATUM,'J')||TO_CHAR(TESZT002_TABLA(J).SOR)
        LOOP
         I:=I+1;
        END LOOP;
        DBMS_OUTPUT.PUT_LINE(I);
        DBMS_OUTPUT.PUT_LINE(J);
        VALTOZO_ELEMZO.EXTEND(I-J-1);
        VALTOZO_ELEMZO(1):=1;
        DBMS_OUTPUT.PUT_LINE(VALTOZO_ELEMZO(1));
        /*EXECUTE IMMEDIATE '
          DECLARE 
            K NUMBER(38);
            LOOP_COUNT NUMBER(38);
          BEGIN
          LOOP_COUNT:=:1-:2-1;
          FOR K IN 1..LOOP_COUNT LOOP
            :3(K):=:4(:1).'||COLNAME||';
          END LOOP;
          END;' USING IN I, IN J, IN OUT VALTOZO_ELEMZO, IN TESZT002_TABLA;*/
          DECLARE
            K NUMBER(38);
            LOOP_COUNT NUMBER(38);
          BEGIN
            LOOP_COUNT:=I-J-1;
            FOR K IN 1..LOOP_COUNT LOOP
              VALTOZO_ELEMZO(K):=TESZT002_TABLA(J+K-1).ERTEK1;
            END LOOP;
          END;
          DBMS_OUTPUT.PUT_LINE(VALTOZO_ELEMZO(1));
          VALTOZO_ELEMZO.DELETE;
      END LOOP;
      
      DBMS_OUTPUT.PUT_LINE(TESZT002_AZONOSITO(1).AZONOSITO);
      TESZT002_AZONOSITO.DELETE;
    END LOOP;
    END;
    Published by: csiszgab on February 4, 2010 18:40

    Your problem has nothing to do with the COLUMN name as damorgan suggested. Your first question is collection: 3 must be extended before that you can add items. Unfortunately, you cannot apply attribute collection EXTEND to a connection variable:

    SQL> create or replace type emp_obj_type as object(ename varchar2(20), sal number);
      2  /
    
    Type created.
    
    SQL> create or replace type emp_tbl_type as table of emp_obj_type
      2  /
    
    Type created.
    
    SQL> SET SERVEROUTPUT ON
    SQL> DECLARE
      2  I NUMBER := 2;
      3  J NUMBER := 0;
      4  COLNAME VARCHAR2(20) := 'ename';
      5  VALTOZO_ELEMZO sys.OdciVarchar2List := sys.OdciVarchar2List();
      6  TESZT002_TABLA emp_tbl_type := emp_tbl_type(emp_obj_type('Sam',1000),emp_obj_type('Joe',1500));
      7  BEGIN
      8  EXECUTE IMMEDIATE '
      9        DECLARE
     10          K NUMBER(38);
     11          LOOP_COUNT NUMBER(38);
     12        BEGIN
     13        LOOP_COUNT:=:1-:2-1;
     14        FOR K IN 1..LOOP_COUNT LOOP
     15          :3(K):=:4(:1).'||COLNAME||';
     16       END LOOP;
     17        END;' USING IN I, IN J, IN OUT VALTOZO_ELEMZO, IN TESZT002_TABLA;
     18  FOR K IN 1..VALTOZO_ELEMZO.COUNT LOOP
     19    DBMS_OUTPUT.PUT_LINE(VALTOZO_ELEMZO(K));
     20  END LOOP;
     21  END;
     22  /
    DECLARE
    *
    ERROR at line 1:
    ORA-06531: Reference to uninitialized collection
    ORA-06512: at line 8
    ORA-06512: at line 9
    
    SQL> DECLARE
      2  I NUMBER := 2;
      3  J NUMBER := 0;
      4  COLNAME VARCHAR2(20) := 'ename';
      5  VALTOZO_ELEMZO sys.OdciVarchar2List := sys.OdciVarchar2List();
      6  TESZT002_TABLA emp_tbl_type := emp_tbl_type(emp_obj_type('Sam',1000),emp_obj_type('Joe',1500));
      7  BEGIN
      8  EXECUTE IMMEDIATE '
      9        DECLARE
     10          K NUMBER(38);
     11          LOOP_COUNT NUMBER(38);
     12        BEGIN
     13       LOOP_COUNT:=:1-:2-1;
     14        FOR K IN 1..LOOP_COUNT LOOP
     15          :3.extend;
     16          :3(K):=:4(:1).'||COLNAME||';
     17        END LOOP;
     18        END;' USING IN I, IN J, IN OUT VALTOZO_ELEMZO, IN TESZT002_TABLA;
     19  FOR K IN 1..VALTOZO_ELEMZO.COUNT LOOP
     20    DBMS_OUTPUT.PUT_LINE(VALTOZO_ELEMZO(K));
     21  END LOOP;
     22  END;
     23  /
    DECLARE
    *
    ERROR at line 1:
    ORA-06550: line 8, column 8:
    PLS-00110: bind variable '3.EXTEND' not allowed in this context
    ORA-06512: at line 8
    
    SQL> 
    

    To resolve this problem, you must declare a variable local collection and assign it to: 3 before returning. However, it changes the variable sequence bind then we need to change the reference of variable binding: 3: 4 and: 4: 3:

    SQL> DECLARE
      2  I NUMBER := 2;
      3  J NUMBER := 0;
      4  COLNAME VARCHAR2(20) := 'ename';
      5  VALTOZO_ELEMZO sys.OdciVarchar2List := sys.OdciVarchar2List();
      6  TESZT002_TABLA emp_tbl_type := emp_tbl_type(emp_obj_type('Sam',1000),emp_obj_type('Joe',1500));
      7  BEGIN
      8  VALTOZO_ELEMZO.extend(2);
      9  EXECUTE IMMEDIATE '
     10        DECLARE
     11          K NUMBER(38);
     12          LOOP_COUNT NUMBER(38);
     13          VALTOZO_ELEMZO_LOCAL sys.OdciVarchar2List := sys.OdciVarchar2List();
     14        BEGIN
     15        LOOP_COUNT:=:1-:2-1;
     16        FOR K IN 1..LOOP_COUNT LOOP
     17          VALTOZO_ELEMZO_LOCAL.extend;
     18          VALTOZO_ELEMZO_LOCAL(K):=:3(:1).'||COLNAME||';
     19        END LOOP;
     20        :4 := VALTOZO_ELEMZO_LOCAL;
     21        END;' USING IN I, IN J, IN TESZT002_TABLA, IN OUT VALTOZO_ELEMZO;
     22  FOR K IN 1..VALTOZO_ELEMZO.COUNT LOOP
     23    DBMS_OUTPUT.PUT_LINE(VALTOZO_ELEMZO(K));
     24  END LOOP;
     25  END;
     26  /
    Joe
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • How to set the value of the variable bind in VO on page load?

    Hello, I use JDeveloper 11.1.2.3.0.

    I created a VO in my application that uses a variable binding in the where clause. I want to put the value of this variable on the loading of the page automatically.

    I read that I can do this through setNamedWhereClauseParam()... but I can't find out where and how to use it.

    Can anyone help please?

    You can put in different places:

    AppModuleImpl,

    ViewObjectImpl,

    ViewRowImpl

    Just him export the customer interface and use whenever you want

  • How to use FOLLOW-UP and COMPRESS the clause of the CREATE statement TABLE?

    my oracle's 10g and the statement of create table below:

    CREATE TABLE S005.q100

    (

    Q1 tank (1)

    )

    NOMONITORING;

    After you create this table, I ask USER_TABLES, but the value of the follow-up column is YES.

    I think there should be no how is? and also I have the same problem with the COMPRESS.

    Thank you very much


    Hello

    Heap - organized tables are your usual routine tables. It is created using the BUNCH of the ORGANIZATION of the CREATE TABLE statement clause. This is the default value.

    The other variant of this clause is ORGANIZATION INDEX, which means that you will create an organized Index of Table. In other words, it is a table that is stored in a B-tree, like an index.

    You also have an EXTERNAL BODY, which means that you will create an external table. Here is generally flat files outside of the database that you can order the database to see tabular to use SQL (read only) against. You will also need the settings on how the data are presented on the file, so that your database knows which column will match that of the data.

    The COMPRESS on 10G is known as the "basic compression" and it works on ordinary table segment blocks, which are organized by a bunch of tables.

  • How to use the record type as a parameter IN PL/SQL procedure or package

    Hi people,

    I need help on the record as the OUT parameter type. I am able to get out a single line as a parameter, but not getting do not idea how to get a multi ranks as output parameter.

    I have the code that works very well for a single line. Please see CODE1.

    But when I try to get several lines, I'm failing to do. Please see the CODE2. I get the error of compilation as


    Error report:

    ORA-06550: line 11, column 35:

    PLS-00487: Invalid reference to the variable "P_NAME.

    ORA-06550: line 11, column 1:

    PL/SQL: Statement ignored

    06550 00000 - "line %s, column % s:\n%s".

    * Cause: Usually a PL/SQL compilation error.

    Any help or a sample execution of script would be really useful.

    Thanks in advance.

    YZ

    --------------------------CODE1------------------------------------------

    -------------------------Package Spec-------------------------------

    CREATE OR REPLACE

    PACKAGE xx_sample_pkg as

    --

    Xx_sample_table_rectype RECORD TYPE IS

    (p_name varchar2 (40))

    number of p_emp_id

    );

    PROCEDURE xx_sample_prc (xx_sample_rec1, OUT xx_sample_table_rectype);

    END xx_sample_pkg;

    ------------------------------Package Body------------------------

    create or replace

    PACKAGE xx_sample_pkg AS BODY

    --

    PROCEDURE xx_sample_prc (xx_sample_rec1 OUT xx_sample_table_rectype) IS

    BEGIN

    SELECT ename, empno

    IN xx_sample_rec1

    FROM scott.emp

    WHERE ename = 'SMITH ';.

    END xx_sample_prc;

    END xx_sample_pkg;

    -------------------------------------------Execute----------------------

    DECLARE

    l_rec_type xx_sample_pkg.xx_sample_table_rectype;

    BEGIN

    dbms_output.put_line ('xx_sample_prc appeal');

    xx_sample_pkg.xx_sample_prc (l_rec_type);

    dbms_output.put_line ('YZ' | l_rec_type.p_name |') '|| l_rec_type.p_emp_id);

    END;

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

    -------------------------CODE2-------------------------------------------

    -------------------------Package Spec-------------------------------

    CREATE OR REPLACE

    PACKAGE xx_sample_pkg as

    --

    Xx_sample_table_rectype RECORD TYPE IS

    (p_name varchar2 (40))

    number of p_emp_id

    );

    PROCEDURE xx_sample_prc (xx_sample_rec1, OUT xx_sample_table_rectype);

    END xx_sample_pkg;

    ------------------------------Package Body------------------------

    create or replace

    PACKAGE xx_sample_pkg AS BODY

    --

    PROCEDURE xx_sample_prc (xx_sample_rec1 OUT xx_sample_table_rectype) IS

    BEGIN

    SELECT ename, empno

    IN xx_sample_rec1

    FROM scott.emp;

    END xx_sample_prc;

    END xx_sample_pkg;

    -------------------------------------------Execute----------------------

    DECLARE

    l_rec_type xx_sample_pkg.xx_sample_table_rectype;

    BEGIN

    dbms_output.put_line ('xx_sample_prc appeal');

    xx_sample_pkg.xx_sample_prc (l_rec_type);

    for l_rec in 1.l_rec_type.p_name.count

    loop

    dbms_output.put_line ('YZ' | l_rec_type.p_name (l_rec) |) » '|| l_rec_type.p_emp_id (l_rec));

    end loop;

    end;

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

    bb8c573a-6ca3-4d7c-90ed-e55c2df67201 wrote:

    But now, my question would be why the record type could not be used? My understanding is missing some concept between use of type type array collection record vs. Please specify.

    Do not confuse the folder with the collection.

    SY.

  • How to use a UUID type number instead of sequence as a default value in the attribute of the view object?

    Hi all.. I want to use a type UUID number in an attribute of the object from view as default value to generate the unique field... so, how can I generate random uuid?

    Well, the UUID looks like as follows:

    Example 1: 067e6162-3b6f-4ae2-a171-2470b63dff00

    Example 2: 54947df8-0e9e-4471-a2f9-9af509fb5889

    You can play withgetMostSignificantBits() and getLeastSignificantBits() , this is the long values and you can combine them in order to generate BigInteger, as described here:

    https://gist.github.com/berezovskyi/2c4d2a07fa2f35e5e04c

    Then just use this value in the constructor number:

    http://docs.Oracle.com/CD/E12839_01/apirefs.1111/e10655/Oracle/JBO/domain/number.html#number%28Java.math.BigInteger%29

  • How to use the functions Timestampadd/Timestampdiff variable repository

    Hello - I tried to build a block of initialization with Variables of repository to fill for below mentioned scenarios. In the EDIT SOURCE of the initialization block, I was trying to write the suite of applications:

    Select

    TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR FROM CURRENT_DATE) *-(1) + 1, CURRENT_DATE) as F_DAY_CY,

    TIMESTAMPADD (SQL_TSI_YEAR-1, TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR FROM CURRENT_DATE) *-(1) CURRENT_DATE + 1)) as F_D_PY,

    ......

    ......

    ......

    Double;

    for which he throws following error thus failing to create the initialization block. Enjoy all the entries on this error.

    init error.png




    Behold, I wanted to create for variables


    First day of current year

    TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR CURRENT_DATE) *-(1) + 1, CURRENT_DATE)

    First day of the previous year

    TIMESTAMPADD (SQL_TSI_YEAR-1, TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR CURRENT_DATE) *-(1) CURRENT_DATE + 1))

    First day of the new year

    TIMESTAMPADD (SQL_TSI_YEAR, 1, TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR CURRENT_DATE) *-(1) CURRENT_DATE + 1))

    First day of the previous month

    TIMESTAMPADD (SQL_TSI_MONTH-1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-(1) CURRENT_DATE + 1))

    First day of the current month

    TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-(1) + 1, CURRENT_DATE)

    First day of the following month

    TIMESTAMPADD (SQL_TSI_MONTH, 1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-(1) CURRENT_DATE + 1))

    Last day of the previous month

    TIMESTAMPADD (SQL_TSI_DAY,-(1), TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-(1) CURRENT_DATE + 1))

    Last day of the current month

    TIMESTAMPADD (SQL_TSI_DAY, TIMESTAMPADD (1), (SQL_TSI_MONTH, 1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-(1) CURRENT_DATE + 1)))

    Last day of the following month

    TIMESTAMPADD (SQL_TSI_DAY, TIMESTAMPADD (1), (SQL_TSI_MONTH, 2, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-(1) CURRENT_DATE + 1)))

    Last day of the previous year

    TIMESTAMPADD (SQL_TSI_DAY-1, TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR CURRENT_DATE) *-(1) CURRENT_DATE + 1))

    Last day of the current year

    TIMESTAMPADD (SQL_TSI_YEAR, 1, TIMESTAMPADD (SQL_TSI_DAY-1, TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR CURRENT_DATE) *-(1) CURRENT_DATE + 1)))

    Last day of next year

    TIMESTAMPADD (SQL_TSI_YEAR, 2, TIMESTAMPADD (SQL_TSI_DAY-1, TIMESTAMPADD (SQL_TSI_DAY, EXTRACT (DAY_OF_YEAR CURRENT_DATE) *-(1) CURRENT_DATE + 1)))

    Thank you!

    Hello

    Pool use in your init block, you had to choose a connection pool to use for the query, so the code to be used in an init block isn't OBIEE LSQL but it is true SQL based on the database of your connection.

    So it depends on if your connection pool to connect to Oracle DB, SQL Server, or another type of database for the syntax to use in your query for date calculations.

  • How to use the clause type conditionally create new lines

    This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.

    The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.

    I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.

    SQL features tutorials - Clause TYPE

    http://www.sqlsnippets.com/en/topic-11663.html

    This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."

    Line - MODEL method string

    http://www.sqlsnippets.com/en/topic-11987.html

    The solution to this link uses this line of source:

    POSITION KEY VAL

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

    R08 0 v1, v2, v3,.

    and this result set:

    POSITION KEY VAL

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

    R08 1 v1

    R08 2 v2

    R08 3 v3

    The reason why it produces that result set is this clause of the statement of MODEL

    RETURN THE UPDATED LINES

    If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.

    Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.

    For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.

    This is the sample data source

    with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
    Select Union all 2, 'b', 'ghi', 'jkl' from dual
    Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Union all select 4, 'f', 'stu', 'vwx' from dual
    )
    Select the key, value, col2, col3
    t

    KEY, VALUE, COL2, COL3
    1, a, abc, def
    2, b, GHI, jkl
    3, "c, d, e, mno, pqr.
    4, f, stu, vwx

    Lines 1, 2 and 4 only have a value of (a, b, c respectively.

    Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set

    Value of the key, col2 col3
    1 an abc def
    2B ghi jkl
    3 c mno, pqr
    3 d mno, pqr
    3 e mno, pqr
    4 f stu vwx

    The nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.

    How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.

    I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.

    We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.

    Like this?

    SQL > with t as
    () 2
    3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double


    Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
    5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
    7)
    8. Select the key
    9, key_1
    10, val
    11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
    12, col2
    13, col3
    14 t
    model 15
    16 partition by (key)
    dimension (1 key_1) 17
    18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
    19 rules
    (20)
    21 val [for 1 to increment of len key_1 [1] 1] = val [1]
    22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
    23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
    24)
    25 order
    26 by key
    27, key_1;

    KEY KEY_1 VAL VAL_N NECK NECK
    ---------- ---------- ----- ----- --- ---
    1 1 has an abc def
    2 b 1 b ghi jkl
    3 1 c, d, e c mno pqr
    3 2 c, d, e d mno pqr
    3 3 c, d, e e mno pqr
    4 1 f f stu vwx

    6 selected lines.

  • How do choices about Collection types

    I am trying to recover data using its giving collection objects
    ORA-01427: einreihig subquery returns more than one line, but if I use slider nested its working fine.


    (Patient) CREATE TABLE
    number of patid
    fname varchar2 (25).
    name varchar2 (25)
    );


    INSERT INTO patient
    (
    patid, fname lastname
    )
    VALUES (1, 'Pat1_FirstName', 'Pat1_Lastname');

    INSERT INTO patient
    (
    patid, fname lastname
    )
    VALUES (2, 'Pat2_FirstName', 'Pat2_Lastname');


    CREATE TABLE patient_add)
    number of patid
    address1 varchar2 (50).
    address2 varchar2 (50).
    State varchar2 (2),
    zip of varchar2 (5)
    );



    INSERT INTO patient_add
    (
    Address1, Address2, State, patid, zip
    )
    VALUES (1, 'first Add1', 'Add2', 'NJ', ' 08817');

    INSERT INTO patient_add
    (
    Address1, Address2, State, patid, zip
    )
    VALUES (1, 'second Add1', 'Add2', 'CT', ' 04461');



    SELECT a.*, cursor (SELECT b.patid, b.address1, b.address2, b.state, zip
    OF patient_add b
    WHERE a.patid = b.patid
    )
    address
    OF THE patient;

    PATID FNAME LASTNAME ADDRESS
    1 Pat1_FirstName Pat1_Lastname (CURSOR)
    2 Pat2_FirstName Pat2_Lastname (CURSOR)

    Its working fine

    CREATE TYPE pat_obj
    AS
    OBJECT (patid number, varchar2 fname (25), name varchar2 (25))


    CREATE TYPE pat_add_obj
    AS
    OBJECT)
    number of patid
    address1 varchar2 (50).
    address2 varchar2 (50).
    State varchar2 (2),
    zip of varchar2 (5)
    )


    CREATE or REPLACE TYPE pat_add_col IS TABLE OF THE pat_add_obj


    CREATE TYPE pat_det_obj AS OBJECT (pat pat_obj, pat_add_list pat_add_col)


    CREATE or REPLACE TYPE pat_det_obj_col IS TABLE OF THE pat_det_obj


    SELECT pat_det_obj_col (pat_det_obj (pat_obj (patid, fname, lastname),
    (SELECT pat_add_col (pat_add_obj (b.patid,
    b.Address1,
    b.address2,
    b.State,
    zip
    ))
    OF patient_add b
    WHERE a.patid = b.patid)
    )
    )
    PATIENT one

    -ORA-01427: einreihig subquery returns multiple rows

    Anyway, is that we can make selection with PL/SQL

    Thank you
    Alen
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    Try

    select pat_det_obj_col (
              pat_det_obj (
                 pat_obj (patid, fname, lastname),
                 cast (
                    multiset (
                       select b.patid, b.address1, b.address2, b.state, zip
                         from patient_add b
                        where a.patid = b.patid) as pat_add_col)))
      from patient a
    
  • How to use a value in a variable as a table name in a query?

    I fetch a value in a variable like:

    < select application_short_name in the fnd_application l_appl_nm where application_id =: p_appl_id >

    Now, I need to use the value retrieved in the variable "l_appl_nm" as a name of partition table in the following query.

    Anyone can guide me please on this concept.

    Expected answers as soon as possible!

    Create dynamic SQL statements with your variable, and then run this SQL with the "EXECUTE IMMEDIATE" command.

    Thank you

    Lokesh

  • How to use the command the reel with Bind Variables

    For the next REEL, I want the GEN_DATE to be entered by the user at the time of execution of the SQL Script. Is this possible in the command of the COIL.


    the colsep value,-separate the columns with a comma
    set pagesize 1000 - get rid of disturbing - between pages
    set position-the title of column Print
    Set trimspool on - remove the spaces to the right. eliminating spaces until eol
    set linesize 700 - line size should be the sum of the column width
    coil spool_results.csv
    SELECT *.
    OF GUI_SITE_JOURNAL
    WHERE GENDATE_ BETWEEN ' 2012-11-01 00:00:00:00000' AND ' 2012 - 11 - 02 00:00:00:00000'* ORDER BY GEN_DATE;
    spool off;

    The reason is to give the opportunity to the user so that he can enter any beach without changing the code of the script.

    Can someone help me please.

    Published by: user10903866 on February 18, 2013 19:44

    Hello

    user10903866 wrote:
    For the next REEL, I want the GEN_DATE to be entered by the user at the time of execution of the SQL Script. Is this possible in the command of the COIL.

    Do you want user input in the command of the COIL, or want you she in the query?

    the colsep value,-separate the columns with a comma
    set pagesize 1000 - get rid of disturbing - between pages
    set position-the title of column Print
    Set trimspool on - remove the spaces to the right. eliminating spaces until eol
    set linesize 700 - line size should be the sum of the column width
    coil spool_results.csv
    SELECT *.
    OF GUI_SITE_JOURNAL
    WHERE GENDATE_ BETWEEN ' 2012-11-01 00:00:00:00000' AND ' 2012 - 11 - 02 00:00:00:00000'* ORDER BY GEN_DATE;

    What are the data type gen_date of the oif?
    If it is a string, it is a big mistake. Information about the dates in the DATE columns belongs.
    If it's a DATE, so don't try to compare strings, such as "2012-11-01 00:00:00:00000'."

    spool off;

    The reason is to give the opportunity to the user so that he can enter any beach without changing the code of the script.

    Can someone help me please.

    One way to do that is with substitution variables:

    ...
    SET     VERIFY  OFF
    
    ACCEPT  start_gen_date     PROMPT "Starting date (e.g., 2013-02-18 23:00:00.00000): "
    ACCEPT  end_gen_date     PROMPT "Ending date   (e.g., 2013-02-18 23:59:59.99999): "
    
    SPOOL  spool_results.csv
    
    SELECT    *
    FROM        gui_site_journal
    WHERE        gen_date  BETWEEN '&start_gen_date'
                    AND     '&end_gen_date'
    ORDER BY  gen_date;
    
    SPOOL  OFF
    

    There are security considerations. Variables substitution to the devious users the power to issue a SQL, such as DROP TABLE command. Users with SQL * Plus access already have this power, anyway.

  • How to use a switch with a variable null?

    Here's my current situation...

    I have a form that will take the information entered in the field "LEDIR" and divide by the information contained in the field "AMMUNITION".  I get errors when the form is loaded first because the "AMMO" field is empty and a problem of "division by 0".   I tried to solve the problem with a switch, but an not sure how to create a 'null' switch box.  This is what I have... any ideas on how I can put the second case it returns a '0' for a field null of AMMUNITION?

    var InvR = this.getField("LEDIR").valueAsString;
    var AmmoPk = this.getField("AMMO").valueAsString;

    switch (ammunition)
    {
    case '0 ':
    Event.Value = 0;

    break;

    case '[what to put here?]. :

    Event.Value = 0;

    break;
    by default:
    Event.Value = (Math.floor (InvR/AmmoPk))
    }

    any ideas on how I can configure the second case , it returns a '0' when the AMMUNITION field is empty?

    Use an empty string:

Maybe you are looking for