Function index and virtual columns

I just read the documentation of Oracle on the FBI. In the context of optimization with a function-based index, it is said that "a virtual column is useful for speed of access to data from expressions.". Here is the link Index-Organized Tables and indexes.

My question is, does Oracle already not create a virtual column when we create a function-based index?

Concerning

Charlie

Hi Charlie
Yes, the database engine creates a virtual column. But this column is hidden. Reproduced in 11.2.0.3 example:
SQL> CREATE TABLE t (n NUMBER);SQL> CREATE INDEX i ON t (round(n,0));
SQL> SELECT column_name, hidden_column, virtual_column  2  FROM user_tab_cols
  3  WHERE table_name = 'T';

COLUMN_NAME                    HIDDEN VIR
------------------------------ ------ ---
N                              NO    NO
SYS_NC00002$                  YES    YES

HTH

Chris Antognini

Troubleshooting performance Oracle, Apress 2008/2014

Tags: Database

Similar Questions

  • Function index and user_tab_cols

    Why an entry is created in user_tab_cols when we create a function based on a column in a table?

    create table t1(a varchar2(100), b number); 

    select * from user_tab_cols where table_name = 'T1'; -- Two rows coming 

    create index idx1 on t1(upper(a));

    select * from user_tab_cols where table_name = 'T1'; -- Three rows coming

    What is the reason to put an entry in user_tab_cols?

    Martin Preiss wrote:

    If I remember correctly there is also a VIRTUAL_COLUMN attribute in % _TAB_COLS (at least since 11.1).

    Yes, there is, but how it would be useful to determine if the column is the index of based function related? All not stored in the disk column is a virtual column:

    SQL > create table (tbl)
    Number 2,
    3 the number n
    4                  )
    5.

    Table created.

    SQL > create index tbl_idx1 on tbl (abs (n));

    The index is created.

    SQL > alter table tbl
    2. Add n_ceil number generated always as (ceil (n));

    Modified table.

    SQL > alter table tbl change invisible n_ceil;

    Modified table.

    SQL > create index tbl_idx2 on tbl (n_ceil);

    The index is created.

    SQL > select column_id,.
    2 column_name
    virtual_column 3,.
    4 hidden_column
    5 to user_tab_cols
    6 where table_name = "TBL";

    COLUMN_ID COLUMN_NAME HIDDEN VIR
    ---------- ------------------------------ --- ---
    1 ID                             NO  NO
    2 N                              NO  NO
    SYS_NC00003$ YES YES
    N_CEIL YES YES

    SQL >

    As you can see, the two SYS_NC00003$ and N_CEIL are hidden, virtual columns. This part is the same regardless of the version. And in 12 c with the invisible support of solumn, you can't count on the id of null column. That's why (or at least one of the reasons) Oracle introduced another column in the view _TAB_COLS in 12 c - USER_GENERATED:

    SQL > select column_id,.
    2 column_name
    virtual_column 3,.
    hidden_column 4,.
    5 user_generated
    user_tab_cols 6
    7 where table_name = "TBL";

    COLUMN_ID COLUMN_NAME VIR HID USE
    ---------- ------------------------------ --- --- ---
    1 NOT ONLY ID YES
    2 N NO NO YES
    SYS_NC00003$ YES YES NO
    N_CEIL YES YES YES

    SQL >

    Now, we can say column SYS_NC00003$ is related FBI.

    SY.

  • Function Index and Query Rewrite

    Hi members,


    I just stumbled on something that I've never thought of before.

    It has to do with the function according to index and (possibly re - write query)

    Here is my configuration:
    SQL> create table tab1 (
      2    x   varchar2 (1)   default 'N' not null check (x in ('Y', 'N')),
      3    y   varchar2 (100) not null
      4  );
    
    Table created.
    
    SQL> create index tab1ix on tab1 (NULLIF(x,'N'));
    
    Index created.
    
    SQL> insert into tab1 (y)
      2    (select rpad (level,100,'x') from dual connect by level <= 1000);
    
    1000 rows created.
    
    SQL> insert into tab1 (x,y) values ('Y', 'Hello there');
    
    1 row created.
    
    SQL> commit
      2  /
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats(user, 'tab1', cascade => true)
    
    PL/SQL procedure successfully completed.
    So, I created a small table with a FBI.

    Now, let's use it.
    The first is a query that obviously do not use it.
    Second, one is a query that corresponds to the FBI.
    SQL> explain plan
      2     set statement_id = 'st1'
      3     into plan_table
      4  for
      5  select * from tab1 where x = 'Y';
    
    Explained.
    
    SQL> 
    SQL> select plan_table_output
      2    from table(dbms_xplan.display('PLAN_TABLE', 'st1','TYPICAL'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    ----------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost  |
    ----------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |   501 | 51603 |     5 |
    |   1 |  TABLE ACCESS FULL| TAB1 |   501 | 51603 |     5 |
    ----------------------------------------------------------
    
    
    SQL> explain plan
      2     set statement_id = 'st2'
      3     into plan_table
      4  for
      5  select * from tab1 where NULLIF(x,'N') = 'Y';
    
    Explained.
    
    SQL> 
    SQL> select plan_table_output
      2    from table(dbms_xplan.display('PLAN_TABLE', 'st2','TYPICAL'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    ----------------------------------------------------------------------
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost  |
    ----------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |        |     1 |   103 |     1 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| TAB1   |     1 |   103 |     1 |
    |   2 |   INDEX RANGE SCAN          | TAB1IX |     1 |       |     1 |
    ----------------------------------------------------------------------
    
    SQL> 
    No worries, right?
    Everything works as expected, when my predicate corresponds to the FBI, the index is used.


    But here's what surprises me. It seems that the index expression is rewritten then it is created:
    SQL> select column_expression from user_ind_expressions
      2  where index_name = 'TAB1IX';
    
    COLUMN_EXPRESSION
    --------------------------------------------------------------------------------
    CASE "X" WHEN 'N' THEN NULL ELSE "X" END
    
    SQL>
    Questions are now, is this safe? -Does still work?

    Can I trust the optimizer always did a rewrite such as performed when the index was created?


    This index might live throughout the years and many versions of the optimizer. But the expression stays (I guess)

    This is going into production this weekend, so I wanted to hear,
    ideas / comments?


    Best regards
    Peter
    SQL> select *from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Linux: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    PS: NULLIF is nothing else than a syntactic sugar for the CASE expression equivalent?
    docs say:
    The NULLIF function is logically equivalent to the following CASE expression:

    CASE WHEN expr1 = END expr1 expr2 THEN NULL ELSE
    edited by: Peter on February 9, 2012 05:32

    Hi Peter

    In the docs for NULLIF, he said

    The NULLIF function is logically equivalent to the following CASE expression:

    CASE WHEN expr1 = expr THEN ELSE NULL expr1 END 2

    http://docs.Oracle.com/CD/B10501_01/server.920/a96540/functions85a.htm
    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/functions102.htm
    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions116.htm

    Which would explain the behavior you saw. As you pointed out, it is possible that the transformation of NULLIF expression BOX equivalent is likely to change? It seems unlikely - indeed, it seems to be an alias or a macro for the instruction box unless there is some way technically superior to implement this logic, it seems to be here to stay. Certainly, it has remained unchanged since the 9i.

    Not sure how that helps.

    David

  • Addition of virtual column: ORA-12899: value too large for column

    I am using Oracle 11g, OS Win7, SQL Developer

    I'm trying to add the virtual column to my test table, but get ORA-12899: value too large for column error. Here are the details.
    Can someone help me in this?
    CREATE TABLE test_reg_exp
    (col1 VARCHAR2(100));
    
    INSERT INTO test_reg_exp (col1) VALUES ('ABCD_EFGH');
    INSERT INTO test_reg_exp (col1) VALUES ('ABCDE_ABC');
    INSERT INTO test_reg_exp (col1) VALUES ('WXYZ_ABCD');
    INSERT INTO test_reg_exp (col1) VALUES ('ABCDE_PQRS');
    INSERT INTO test_reg_exp (col1) VALUES ('ABCD_WXYZ');
    ALTER TABLE test_reg_exp
    ADD (col2 VARCHAR2(100) GENERATED ALWAYS AS (REGEXP_REPLACE (col1, '^ABCD[A-Z]*_')));
    
    SQL Error: ORA-12899: value too large for column "COL2" (actual: 100, maximum: 400)
    12899. 00000 -  "value too large for column %s (actual: %s, maximum: %s)"
    *Cause:    An attempt was made to insert or update a column with a value
               which is too wide for the width of the destination column.
               The name of the column is given, along with the actual width
               of the value, and the maximum allowed width of the column.
               Note that widths are reported in characters if character length
               semantics are in effect for the column, otherwise widths are
               reported in bytes.
    *Action:   Examine the SQL statement for correctness.  Check source
               and destination column data types.
               Either make the destination column wider, or use a subset
               of the source column (i.e. use substring).
    When I try to, I get the correct results:
    SELECT col1, (REGEXP_REPLACE (col1, '^ABCD[A-Z]*_'))
    FROM test_reg_exp;
    Thank you.

    Yes, RP, it works if you give col2 size > = 400.

    @Northwest - could you please test the same w/o having a clause of regex in col2?
    I have a doubt about using a REGULAR expression in this case Dynamics col.

    Refer to this (might help) - http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
    Below excerpt from above link... see if that helps...
    >
    Notes and restrictions on the virtual columns include:

    The indexes defined on the virtual columns are equivalent to a function-based index.
    Virtual columns can be referenced in the updates and deletions WHERE clause, but they cannot be manipulated by DML.
    The tables containing virtual columns may still be eligible for result caching.
    Functions in expressions must be deterministic when the table is created, but can then be recompiled and non-deterministic without for as much invalidate the virtual column. In such cases, the following steps must be taken after the function is recompiled:
    Constraint on the virtual column must be disabled and re-enabled.
    On the virtual column indexes must be rebuilt.
    Materialized views that access the virtual column must be fully refreshed.
    The result cache must be flushed if the virtual column acceded to the request (s).
    Statistical table must be regathered.
    The virtual columns are not supported for the organized and external object in index, cluster or temporary tables.
    The expression used in the virtual column definition has the following restrictions:
    It cannot refer to another virtual column by name.
    It can refer to the columns defined in the same table.
    If it refers to a deterministic user-defined function, it cannot be used as a partitioning key column.
    The result of the expression must be a scalar value. It cannot return that an Oracle supplied the data type, a type defined by the user, LOB or LONG RAW.
    >

    Published by: Vanessa B on October 16, 2012 23:48

    Published by: Vanessa B on October 16, 2012 23:54

  • details of the virtual columns and deterministic function

    Hello

    First time that I post a question after the migration of the Forums. So please excuse me if you see errors in format.

    Below, I have created a function as deterministic and a table with a virtual column (column refers to the function)

    Here are my questions

    (1) if I run SELECT * FROM t whenever Oracle will perform the function add_fn?

    (2) what is the advantage of DETERMINISTIC? (Documentation says that if we declare a function as deterministic he will attempt to use previously caluculated results for the same set of values. So, when I ever I run SELECT * FROM t oracle executes add_fn only once and it will use the result for the next time. Is my understanding correct.)

    Here's the code.

    SQL> create or replace function add_fn ( p_n1 in number
      2                                                   ,p_n2 in number )
      3  return number deterministic
      4  is
      5  begin
      6      return p_n1+p_n2;
      7  end;
      8  /
    Function created
    SQL> create table t ( n1 number
      2                       ,n2 number
      3         ,n3 number generated always as (add_fn(n1,n2)) virtual
      4         );
    Table created
    SQL> insert into t (n1,n2) values (10,20);
    1 row inserted
    SQL> select * from t;
            N1         N2         N3
    ---------- ---------- ----------
            10         20         30
    SQL> select * from t;
            N1         N2         N3
    ---------- ---------- ----------
            10         20         30
    SQL>
    

    Hello

    ...
    (1) if I run SELECT * FROM t whenever Oracle will perform the function add_fn?

    (2) what is the advantage of DETERMINISTIC? (Documentation says that if we declare a function as deterministic he will attempt to use previously caluculated results for the same set of values. So, when I ever I run SELECT * FROM t oracle executes add_fn only once and it will use the result for the next time. Is my understanding correct.)

    ...

    (1) oracle will have to evaluate the function.  Because only deterministic functions are allowed, this means that it will not necessarily perform the function again; He can get the value cached from a previous call.

    I think that the indexed values are actually stored in the index.  "SELECT * FROM t;" do not use an index, but if you make another request, then you should be able to get the value of the virtual table of the index, without calling the function or obtaining the value of a cache.

    (2) If a function is DETERMINISTIC, the optimizer may decide whether to actually call the function each time, or the cache for better performance results.  There is no guarantee that it will always be one or the other.  Replace "will be" in your description "may", and then what you say is correct.

  • Index on two columns becomes the index of function?

    Hello, I create a unique index with two columns, a number (9) and a date.

    It becomes an index of feature based with the number column and a column sys hidden (date).

    When I do queries that use this index the autotrace tells me it does things like this:

    sys_nc00001$ > SYS_OP_DESCEND (datevalue)
    sys_nc00001$ IS NOT NULL

    How is he did not have a normal index?

    Use of ESCR does this.

    Of http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm

    Oracle database processes Index descending as if they were focused on the index function.

  • index on the column using custom function

    Can we create index on the column using custom function?

    http://www.dbasupport.com/Oracle/ora8/FBI.shtml

    Kind regards
    Kaila Mahesh

  • Indexing and the integrity constraint functionality difference

    Hello

    Sometimes I confuse me, how we can distinguish between indexing and the integrity of the features of constraint. Please let me know or if any available doc.


    Kind regards
    REDA

    I assume you mean unique vs unique index constraints?

    The sole (or Primary Key) constraints provide additional metadata that can be used by the optimizer.
    An index will be used to help the database to apply the constraint (it is created, or if there is it will be "captured" by coercion)

    Insofar as a document [url http://docs.oracle.com/cd/E11882_01/server.112/e25789/toc.htm] that's something, you should read

  • Problem indexing and performance does not help

    I created a SQL view is basically simple, but I need to group data based on a value returned by a function. I think this slows down the performance. First, I added a normal index on it, then added that an index function but no help. I get the data I need, but it takes too much time. I hope someone can give me some ideas on how to optimize the performance of my SQL.

    The base table has 1318408 rows. I need to select only a few columns and group and count the rows based on a date value in a column. However, the date of the table contains only a weekend rental value and I need report of the neighborhoods. The report should as well a date and value of a text value for the quarter. So I created two functions that accept a date value and return a date value for the start date of the quarter and a text value for the quarter, that the date falls in respectively; my SQL is like this:

    Select
    GLC_DATE2CAL_QRT_STARTDATE_FN (s.work_week_end_date) cyquarter_start_date,
    GLC_DATE2CAL_QRTYR_FN (s.work_week_end_date) cyquarter_text,
    s.Ethnicity ethnicity_code,
    and. Description ethnicity_desc,
    County (unique employee_id) number_employees
    of s cpr_employees_snapshot, ct_vendor_ethnicities and
    and trim (s.ethnicity) = et.ethnicity_id
    Group GLC_DATE2CAL_QRT_STARTDATE_FN (s.work_week_end_date), GLC_DATE2CAL_QRTYR_FN (s.work_week_end_date), s.ethnicity, et.description

    This takes about 1 1/2 minutes to recover data

    When I do not use the functions and run this SQL:

    Select
    s.work_week_end_date,
    s.Ethnicity ethnicity_code,
    and. Description ethnicity_desc,
    County (unique employee_id) number_employees
    of s cpr_employees_snapshot, ct_vendor_ethnicities and
    and trim (s.ethnicity) = et.ethnicity_id
    Group of s.work_week_end_date, s.ethnicity, et.description

    It takes 7 seconds.

    Hello

    Welcome to the forum!

    You feel the change of context, where you constantly change between SQL and PL/SQL. That always takes time.

    A function-based index can help if you have referenced only functions in the WHERE clause. Given that you use in the SELECTION and GROUP BY clauses, it cannot help.

    What are the functions? Maybe you could calculate their in a subquery, with pure SQL expressions.

    From Oracle 11, you can have virtual columns that are computed when you INSERT or update each line and physically stored in the table.
    In previous versions of Oracle, you can get the same results with a materialized view, or a BEFORE INSERT trigger that calls the functions and meets the additional columns.

  • Index on the column of string with uppper?

    Hello

    I have the table containing the primary key of the string column. I want to create the index on the primary key and another column.

    Best solution (for the performance) will be create index higher using as

    ON TABLE (UPPER("ID"), ANOTHER_COLUMN)

    or without SHANK

    ?

    Best regards

    m.

    Hope that the ID is a primary key. If this query will return one row, and it will go for a sweep of unique index. Just remove the UPPER function and do like id = UPPER (value);

    Before removing the UPPERCASE function, make sure that the data will be uppercase in the table.

    Because of the HIGH, it will not hit the Unique index...

  • Function Index

    I'm reviewing an existing table in a database Oracle 11g and I do not understand a function based index that was created. The syntax is less than

    CREATE INDEX abc. Orders_Date on abc. ORDERS

    (CASE WHERE "ORDER_DATE" IS NOT NULL THEN "ORDER_DATE" ELSE NULL END)

    LOGGING;

    This table has about 90 000 lines with 32 000 values distinct order_date, 3000 lines have order_dates null. When you run a query on this table using the order_date column it makes a full table scan.

    What does this function index based? because I do not see how it adds all the required features

    Thank you

    As others have said, this index is actually right on order_date, however, is a core function so it cannot be used in queries that use CASES WHEN "ORDER_DATE" IS NOT NULL THEN END NO OTHER "ORDER_DATE."

    It is assumed that it might be possible that there is an index on (order_date) but it was found that it was used in the sql queries, which would have preferred to use other indexes. Some queries benefits so maybe that option based function was created as the sql must refer to the phrase exactly, requests that have received have been rewritten and others were left so that they could avoid the new index of the index.

    Of course, if this were the case then maybe you can take a look at your stats.

  • Interval partitioning using the key of the virtual column

    Hi guys

    I have a series of tables that I propose to the partition.

    Each table has a year and a period (equivalent to a month) and I intend using those as my partition keys - year as the partition and the period as the subpartition.

    The distribution will be actually:

    2015

    001

    002

    ...

    012

    2016

    001

    002

    ...

    012

    etc...

    I would use range partitioning for the year, because it would make the maintenance of the partition a breeze.  Only one problem - the field is of type varchar, and is not modifiable as its legacy applications that have become bigger than Ben Hurr and more tangled than a Ben Hurr size flat spaghetti.

    It is hence the idea of virtual column between in game - I could create a virtual column in these tables to convert the field to digital and then partition on it instead.

    My question-if the year of origin varchar column is included in the where clause of a query, is the optimizer based on CSSTidy smart enough to realize that the virtual column used for the partition key is based on this column and use pruning of partition to improve performance?  Or queries must refer to the virtual column to make it work?  Also, the virtual column should be indexed to make it work?

    Thanks in advance.


    Simon

    orclz >

    orclz > create table pt (v1 varchar2 (1) c1 as (to_number (v1)), number of c2)

    2 partition by range (c1) interval (1)

    subpartition by hash (c2) subpartitions 4 3

    4 (partition p1 values less than (1))

    5.

    Table created.

    orclz > set autot on explain

    orclz > select * PT where v1 = '0';

    no selected line

    Execution plan

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

    Hash value of plan: 711571056

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |

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

    |  0 | SELECT STATEMENT |      |    82.  2296 |    29 (0) | 00:00:01 |      |      |

    |  1.  RANGE OF PARTITION ALL THE |      |    82.  2296 |    29 (0) | 00:00:01 |    1. 1048575.

    |  2.  HASH PARTITION ALL |      |    82.  2296 |    29 (0) | 00:00:01 |    1.    4.

    |*  3 |    TABLE ACCESS FULL | PT |    82.  2296 |    29 (0) | 00:00:01 |    1. 1048575.

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

    Information of predicates (identified by the operation identity card):

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

    3 - filter ("V1" = '0')

    orclz > select * PT where c1 = 0;

    no selected line

    Execution plan

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

    Hash value of plan: 1726115854

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |

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

    |  0 | SELECT STATEMENT |      |    82.  2296 |    29 (0) | 00:00:01 |      |      |

    |  1.  RANGE OF SINGLE PARTITION |      |    82.  2296 |    29 (0) | 00:00:01 |    1.    1.

    |  2.  HASH PARTITION ALL |      |    82.  2296 |    29 (0) | 00:00:01 |    1.    4.

    |*  3 |    TABLE ACCESS FULL | PT |    82.  2296 |    29 (0) | 00:00:01 |    1.    4.

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

    Information of predicates (identified by the operation identity card):

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

    3 - filter ("C1" = 0)

    --

    John Watson

    Oracle Certified Master s/n

  • json_list to varchar/string to use in the virtual column

    Hello Experts,

    Environment:

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    PL/SQL Release 12.1.0.2.0 - Production

    I have the following function that returns JSON_LIST.

    {code}

    CREATE OR REPLACE FUNCTION GENERATE_JSON (STRING2CONVERT IN VARCHAR2)

    RETURN JSON_LIST

    DETERMINISTIC

    IS

    RET json_list;

    V_ERROR VARCHAR2 (31000);

    BEGIN

    RET: = json_dyn.executeList (STRING2CONVERT);

    RET. Print;

    RETURN RET;

    EXCEPTION WHEN OTHERS THEN

    V_ERROR: = SQLERRM;

    RETURNS A NULL VALUE.

    END;

    -test the query see the output in the output of DBMS

    SELECT GENERATE_JSON (' select ' |) Chr (39) | ' AJ' | Chr (39) |' like c_name,' | Chr (39) | ' BOY ' | Chr (39): ' c_type, like '

    || Chr (39) | ' HUMAN '. Chr (39): ' as c_category,' | Chr (39) | ' TEST SUBJECT ' | Chr (39) | 'as c_desc from dual')

    FROM DUAL;


    {code}


    The SQL query above in the DBMS output output

    [{

    "C_NAME": "AJ."

    "C_TYPE": "BOY."

    "C_CATEGORY": "HUMAN."

    'C_DESC': 'GUINEA PIG '.

    }]


    Question: How can I have it return the same structure of String (varchar).


    Why would I want to convert JSON_LIST to string?

    So that I can use this call to service as part of a virtual column in a table to store Json and have a constraint to enforce structureof Json.


    If this is not the right way?

    Kindly share how I can take a few columns in the same table, convert to json format and store in a virtual column in the same table and enforce the Json structure?


    Thank you

    AJ



    with

    data in the form of

    (select q'~ select "AJ" as c_name, 'BOY' as c_type, 'HUMAN' as c_category, 'SUBJECT of TEST' as the double c_desc ~' source)

    of the double

    ),

    Converter (SRC, res, Step) as

    (select regexp_replace (ltrim (upper (substr (source, 1, instr (upper (source), "FROM") - 1)), "SELECT"), '\s+AS\s+',': ') |) ',', null, 1

    from the data

    Union of all the

    Select substr (src, instr(src,',') + 1)

    '"' || substr (substr (SRC, 1, InStr (CBC, ',') - 1), instr (substr (src, 1, instr (CBC, ',') - 1),': ') + 1) | '" : ' ||

    Replace (substr (substr (SRC, 1, InStr (CBC, ',') - 1), 1, instr (substr (src, 1, instr (CBC, ',') - 1),': ')-1), "','" ' "),

    Step + 1

    converter

    where the CBC is not null

    )

    Select the source'[{' | listagg(res,',') Group (order by step) |}] '] "converted

    data converter

    SOURCE CONVERTED
    Select "AJ" as c_name, 'BOY' as c_type, 'HUMAN' as c_category, 'SUBJECT of TEST' as double c_desc [{'C_NAME': 'AJ', 'C_TYPE': 'BOY', 'C_CATEGORY': 'HUMAN', 'C_DESC': 'GUINEA PIG'}]

    Concerning

    Etbin

  • Function Index problem.

    Hello

    I have a problem regarding a function function index.

    example:

    TableName: Test

    Column: A, B, C, D

    I create the index on the table, column, a test using a user-defined function.

    If I do a select on the column, he'll be fine. In other words, I'll get the results you want.

    However, if I insert in the table and validation, and I do a query using the 'A' column in the where clause. I don't have any query hits. Its really weird.

    Have you ever experienced this problem? and is there an index of function according to back and donts w.r.t.?

    Thank you.

    MichaelR

    If you use a deterministic function really, it works:

    create or replace function test_fn (p_number number) return number deterministic
    is
      vreturn number := 0;
    begin
      if p_number = 1 then vreturn := 55; end if;
      if p_number = 2 then vreturn := 89; end if;
      return vreturn;
    end;
    

    Or, if you reverse the order of your second inserts (insert the folder before the recording of test1 test2) - it works fine.

    The reason why you get no results is when you insert the file test1 with a = 2, Oracle executes the function and gets no data, so it assumes that the result is NULL and puts in the index. You said Oracle function is deterministic, so he starts from the principle that any time test_fn (2) is called, it retrieves a null response.

  • ORA-54002 on creating virtual column

    I wonder on what follows.

    I'm in the middle of a migration project.

    I load the data received from the source database into the staging tables.

    The data in these tables must remain absolutely intact to be able to check where things have gone wrong if something is not the way we expected after migration.

    Obviously, the data includes dates. Those who are in the DATE data type columns.

    However, the values represent the date and time UTC.

    The values are NOT timestamps with time zone, but simply date that contains the date time and something that has passed, but expressed in the date and time utc.

    Now, the database target also expects that DATEs, so I seem to be home free.

    However, the target database expect the passage of time to express the time zones (Europe/Amsterdam).

    No problem I know how to do this.

    And because I want to do a million times in the transformation before insertion in the target code (and almost certainly forget a few times) I thought: I'll add virtual columns for the staging tables that allow to calculate the local time of the date and time utc.

    This way the data is intact, but the transformation code can simply use the column (virtual) replacement and does not bother with the calculations of time.

    Great, I thought.

    Until I tried to create the table.

    CREATE TABLE utc_test

    (createddate_utc DATE

    createddate GENERATED DATE ALWAYS

    AS (CAST (FROM_TZ (CAST (createddate_utc AS TIMESTAMP)

    , "UTC".

    )

    At the time of the ZONE "Europe/Amsterdam".

    AS DATE

    )

    )

    VIRTUAL

    );

    And Oracle says:

    At the time of the ZONE "Europe/Amsterdam".

    *

    ERROR on line 7:

    ORA-54002: only pure functions can be specified in a virtual column expression

    Excuse me?

    Not deterministic?

    Oracle is probably right, and even if it isn't yet I have to live with that.

    But no matter how hard I try I can't understand why this code would not deterministic.

    IMHO any form of date I put in createddate_utc, if I put the same date in here a million times I'll get the same answer a million times.

    I know, FROM_TZ to the ZONE SCHEDULE will give different answers for different time zones.

    But not for a same time zone.

    And is this not the essence of deterministic: always the same result, given the same input?

    Anyone who can teach me Oracle ;-)

    My question (I may not was clear on that) was: why Oracle claims that the function is not deterministic?

    Because this is not the case.

    Zone information (and therefore the conversion between TZs) are governed by the zone files, see: Datetime and time zones Support Data Types.

    Since these data may vary, it is not deterministic.

    To solve this 'problem', you can always create a standalone function transformation of packaging and declare it deterministic, even if it is not in the strict sense.

Maybe you are looking for