Cannot create Index with an If statement

Hello:

I would run the code to create an index on a given table, but only if the index does not exist. Here's what I have so far...

DECLARE
c_Count NUMBER;
BEGIN
SELECT COUNT (*) FROM c_Count
OF DBA_INDEXES
WHERE TABLE_NAME = 'SOME_TABLE_NAME '.
AND INDEX_NAME = "SOME_INDEX_NAME."
AND OWNER = 'SOME_OWNER. '
AND TABLE_OWNER = "SOME_OWNER";
IF c_Count = 0 THEN

CREATE INDEXES SOME_OWNER. SOME_INDEX ON SOME_OWNER. UNE_TABLE (SOME_KEY);
END IF;
END;

The SELECT INTO statement works well alone.
Boredom comes with the IF statement. I get the following error message:

PLS-00103: encountered the symbol "CREATE" when waiting for one of the following values: begin case declare exit for goto if loop...

This is the typical error saying that the syntax is incorrect, and that the parser was expecting something else after the IF-THEN statement. Any ideas on what may be a problem? Thanks in advance.

Jerry

Hello

You must use EXECUTE IMMEDIATE to the DDL in PL/SQL.

DECLARE
   c_Count NUMBER;
BEGIN
   SELECT COUNT(*)
     INTO c_Count
     FROM DBA_INDEXES
    WHERE TABLE_NAME = 'SOME_TABLE_NAME'
      AND INDEX_NAME = 'SOME_INDEX_NAME'
      AND OWNER = 'SOME_OWNER'
      AND TABLE_OWNER = 'SOME_OWNER';
   IF c_Count = 0 THEN
      EXECUTE IMMEDIATE 'CREATE INDEX SOME_OWNER.SOME_INDEX ON SOME_OWNER.SOME_TABLE(SOME_KEY)';
   END IF;
END;

Kind regards

Tags: Database

Similar Questions

  • ORA-02327: cannot create indexes on the LOB data type expression

    DB 10.2.0.4
    DB 5.2

    I am not able to move lobindex and lobsegment. While try occurs below error

    SQL > ALTER INDEX dev. "" SYS_IL0000718396C00002$ $"REBUILD THE TABLESPACE DATA_TEMP;
    ALTER INDEX dev. "" SYS_IL0000718396C00002$ $"REBUILD TABLESPACE DATA_TEMP
    *
    ERROR on line 1:
    ORA-02327: cannot create indexes on the LOB data type expression

    Thank you

    Published by: user13382934 on October 16, 2012 14:05

    correct syntax is
    ALTER TABLE.

    MOVE the LOB ()
    STORE AS (tablespace );

    Where is a name of the / columns LOB, not the name of the segment. Moving type LOB data will move its indexes as well.

  • Create indexes with NOLOGGING option

    Hello

    Can you please provide solution on the following scenario?

    If I create indexes with NOLOGGING Tablespace that is created with the LOGGING option, option can you please let me know what are the effects on the database?

    If I create indexes using NOLOGGING on Tables that are created with the LOGGING option, can you please let me know that it is to increase performance during the creation / rebuild indexes?

    Thank you

    Published by: user12088323 on December 28, 2010 12:45

    Published by: user12088323 on December 28, 2010 12:47

    user12088323 wrote:
    The database is in log mode archive. I would like to create indexes with NOLOGGING option on the tables to increase performance. The tables are created with the LOGGING option. Can you please let me know it's to create a bad effect on the database? If so, please explain.

    Thank you

    Published by: user12088323 on December 28, 2010 16:37

    NOLOGGING will cease to produce data AGAIN... for which you want to execute the instructions.
    Nothing wrong... it is created by ORACLE ;-)

    read this and cross with your process. You can do it with nologging option.

    http://www.Oracle.com/technetwork/database/RDB/0804-NOLOGGING-option-130004.PDF

    hope you understood

  • Cannot create indexes on the flow table

    Hello

    I'm new to ODI.

    The problem is that during the execution of an interface, I get the error of the "IKM Oracle Dimension to slow variation"

    The command in step "Create unique index on the flow table:

    creating index < % = odiRef.getTable ("L", "INT_NAME", "A") % > idx

    on < % = odiRef.getTable ("L", "INT_NAME", "A") % > (< % = odiRef.getColList ("", "[column]", ",", "", "SCD_NK") % >)

    < % = odiRef.getUserExit ("FLOW_TABLE_OPTIONS") % >

    generate the following statement which lacks the name of the column between the (_)

    Create index I$ _MYTABLE_idx

    I have $_MYTABLE)

    NOLOGGING

    The result is that the interface fails with the error 936: 42000: java.sql.SQLException: ORA-00936: lack of expression caused by the previous command wrong.

    Please, can you help me?

    Thank you very much

    Angelo

    Hello

    I'm really really sorry! I just realized that you are working on the SCD. Basically, you are looking for all the column mapped as SCD_NK (key to slowly change natural Dimensions) insofar as shown here

    Substitution QAnywhere

    IF you need to read this

    SCD Type 2 - ODIExperts.com

    Let me know.

  • Cannot create index

    I create a table and create an index on it, as follows:
    SQL > create index t_idx on t online

    It can create indexes successly. Then I fall off the table, as follows:
    SQL > drop table t

    Then I create table t once again, as follows:
    SQL > create table (t)
    x varchar2 (10),
    y varchar2 (20)
    );

    then I create index once again, she triggers errors
    SQL > create index t_idx on t online
    ERROR on line 1:
    ORA-01408: such list already indexed column.

    Why rise above error? So I try to delete the index, as follows:
    SQL > drop index t_idx
    ERROR on line 1:
    ORA-01418: specified index does not exist

    Where's the harm? I'm puzzled with her.
    Thank you

    Hello

    INDEX_OWNER INDEX_NAME
    ------------------------------ ------------------------------
    TABLE_OWNER, TABLE_NAME
    ------------------------------ ------------------------------
    COLUMN_NAME
    --------------------------------------------------------------------------------
    TEST SYS_C005408
    T-TEST
    X

    So, it seems that you still have an index called SYS_C005408 on the X in the column of the Table T.

    You can try to delete this Index:

    drop index TEST.SYS_C005408;
    

    Then try to create the Index T_IDX.

    To find the Alert.log just execute this statement:

    show parameter backgroud_dump_dest
    

    Hope this helps.
    Best regards
    Jean Valentine

    Published by: Lubiez John Valentine, June 1, 2011 07:43

  • Performance problem of creating index with LOB/CLOB content

    Hello

    I have a problem with indexing performance with a table containing columns of text
    also a clob and a lob column.

    Indexing with 20,000 lines takes about 1 hour on 11.2.0.4 with the last batch of patches 12 on
    win x 64.

    on a 11.2.0.1, the process is done in a few minutes.

    So what can I do to find out where is the problem?

    I use filter auto and basic lexer.
    Operating system is W 2008 R2 SP and latest patches. OS lang is English.
    DB is installed with AL32UTF8 and German and English language packs.

    also watched and ctx_user_index_errors and pending and there is no error or waiting in lines.
    After the index is created, everything works fine. during the creation of index no other user is connected to the database.

    so why 11.2.0.1 is so much faster than 11.2.0.4?
    some advice for me?

    Thank you!

    Hello

    so I solved all my problems.

    So I made two changes:

    1. I declared the variable theNotiz2 for recording the output for the raw text of the column NOTIZ (is a clob), add the output to the Out-Clob parameter

    2. I used the same variable for the--> this blob field caused an error with line with lob is not locked... so I said a second variable for this and that solved the problem.

    normally, I think it should work with 1 variable... but is an acceptable workaround.

    Performance now is OK because the procedure, I can set on which the documents I want to do a search or not.

    Second thing, but has nothing to do with Oracle: my frontend application makes a ZIP for each insert in a column lob and if the ctxhx does not index the content, the MDC, and before calling the conversion of plain text, so I have to make a decompression of the blob...

    so for now, all problems solved. Thank you for your support.

  • Created index with DESC with USER_IND_COLUMNS. COLUMN = ' SYS_NC00023$ '.

    On Oracle 11.2, I observed below
    create index ind_jperson_1 on d_jperson(convict_ref);
    create index ind_jperson_2 on d_jperson(driver_ref DESC);
    
    select index_name,table_name,column_name,column_position,descend
      from USER_IND_COLUMNS where  table_name='D_JPERSON'
    
    INDEX_NAME     TABLE_NAME     COLUMN_NAME     COLUMN_POSITION     DESCEND
    IND_JPERSON_2     D_JPERSON     SYS_NC00023$     1     DESC
    IND_JPERSON_1     D_JPERSON     CONVICT_REF     1     ASC
    How to find the true picture of this index column?

    Hello

    DBA_IND_EXPRESSIONS can help you find the real column name.

    And it is an expected behavior in Oracle. Have you noticed anything else pre 11.

    Concerning
    Anurag

  • Failed to create index with imdp

    I am trying to import an image with the following command:

    Impdp user/pass DIRECTORY = SCHEMAS DUMPFILE = fump.dmp = originally_schema REMAP_SCHEMA = originally_schema:new_schema TABLE_EXISTS_ACTION = DATA_PUMP_DIR replace old = REMAP_TABLESPACE: new

    I don't know how the dump has been exported.

    Source DB version: 11.2.0.4

    Destination DB version: 11.2.0.1

    Everything works fine until it comes to the creation of index:

    Processing object type SCHEMA_EXPORT/TABLE/INDEX/DOMAIN_INDEX/INDEX

    ORA-39083: Type what INDEX failed to create object error:

    ORA-06550: line 2, column 1:

    PLS-00306: wrong number or types of arguments in the call to "CREATE_INDEX.

    ORA-06550: line 2, column 1:

    PL/SQL: Statement ignored

    Because sql is:

    BEGIN

    ctxsys.driimp.create_index('I_SRC_NAME','SOURCES',User,'ID','2','NAME','1','1020','32','8130','33',, NULL, NULL, 0,'Y','ON COMMIT','12582912',, NULL, null);

    ctxsys.driimp.set_object('DATASTORE','DIRECT_DATASTORE',0);

    ctxsys.driimp.set_object ('TYPE ',' CHAR_)

    Hope you can help me.

    & then you cannot use V11.2.0.4 expdp use impdp since V11.2.0.1

    expdp should include VERSION = 11.2.0.1

  • CREATE INDEX with ON DUPLICATE

    Hello

    I use Oracle10g Express (v10.2.0). What is given the equivalent query in Oracle for SQL Server query below?

    CREATE UNIQUE INDEX uix_NumberUnique ON UserInfo(UserID, Number)
    WITH (IGNORE_DUP_KEY = ON)

    I appreciate your inputs.

    Thank you
    Jonathan

    Here is an example

    SQL> create table t (no integer primary key);
    
    Table created.
    
    SQL> exec dbms_errlog.create_error_log('T','T_ERR')
    
    PL/SQL procedure successfully completed.
    
    SQL> insert into t
    select no
      from (
              select 1 no from dual union all
              select 2 no from dual union all
              select 1 no from dual
           )
    log errors into t_err('Insert Error') reject limit unlimited;         2    3    4    5    6    7    8  
    
    2 rows created.
    
    SQL> select * from t
      2  /
    
            NO
    ----------
             1
             2
    
    SQL>  exec dev_util.print_table('select * from t_err')
    ----------------------------------------------------------------------------------------------------
    Field Name                      Field Value
    ----------------------------------------------------------------------------------------------------
    ORA_ERR_NUMBER$               : 1
    ORA_ERR_MESG$                 : ORA-00001: unique constraint (ARBORU.SYS_C00407493) violated
    ORA_ERR_ROWID$                :
    ORA_ERR_OPTYP$                : I
    ORA_ERR_TAG$                  : Insert Error
    NO                            : 1
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Cannot create OVF with ESXi ovftool.  Get the error: Server error had

    When I try to create an egg/ovf to a vmx located on an ESXi Server 5.1, or try to check it out, I get an error that seems to indicate that the server or tool seeks the .iso file that was used in the original data store to build the server.

    C:\Program VMware OVF tool > ovftool - verifyOnly "vi://root:vmware@1."

    0.62.222.85:443/staging-DC/VM/HQ-CUCM-01

    Error: Got error on server: ds file: / / / vmfs/volumes/5354c80b-dc197e1f-3639-b83

    861d76de7/ISOs/CUCM-CUC/Bootable_UCSInstall_UCOS_9.1.2.11900-12.Sgn. ISO has not been

    found

    I thought that, perhaps, the server thought that the .iso image file was mounted when I stopped him and that the tool has tried to do something with it, but I turned on and made sure that the .iso image file was not connected.  I tried copying the file that he complained to the data store, following the same directory tree, but it always fails.  Also, the VM was migrated from one server to another. So I don't know if that has anything to do with him or not.

    Any ideas?

    Thanks in advance.

    Thanks for the reply.  I made sure that the ISO has been disconnected (last part of my original question).  But I advanced and changed the setting for the DVD of the .iso in "Client" and who did.

  • Cannot create pdf with the same page size

    Hello

    I installed Adobe Acrobat Professional (writer). And created a pdf document. the pdf file contains images, each on his page. The problem is when I save or preview the document, some images are not sized for his area of page (or fit to page). Please check attached picture to see the problem.

    How can I add images to PDF with eqal size.

    Please check attached picture Pdfsnap1 & Pdfsnap2 (used the crop tool)...

    Someone helped me to visit the following link for the solution:

    http://forums.adobe.com/thread/841095

    Above the provided Adobe forum link is good, but 50% of my problem is solved. In other words, the selection of the image and using her crop tool 'page size' is increased, but the image on the page is still small, or it does not increase with the size of the page.

    Concerning

    Nauman

    pdfsnap.JPGpdfsnap2.JPG

    To resize the image, you need to select with the object tool and drag the buttons on the sides and the corners to resize it.

    Much of what you do can be done in Acrobat, but this isn't the ideal application for such actions. Acrobat isn't really an editing tool, but a tool to create a finished product that provides essentially platform independent product. You might find what you want to do is best done in a word processor or page layout tool, then a PDF file created from this result.

  • Cannot create a with RAC ASM diskgroup

    I have,

    I have 2 W2003 SP2 with Oracle 10 g with RAC and ASM 2.
    I certainly have a few errors to create the diskgroup:
    Stamp the disc on node1
    I create the Group on node1
    Stamp the disc on Node2
    I create the Group on Node2
    I have remove the diskgroup, remove the stamp, but now I can not re - create my group I ORA-15018 and ORA-00600 code kfcMount54.

    Is this a how to completely clean the disc and diskgroup and how to properly add a diskgroup RAC?

    Thanks for your help.

    1) access at metalink.oracle.com

    You must have a support contract with oracle to access to metalink (and you really need one if you want to run cars on a production environment)

    (2) bounce = redΘmarrer

  • Cannot create links with editing in the browser

    Sorry to post this here, but I'm out of options. Three of my clients are unable to create links on their sites using IBE. I tried to reach out to the IBE team on it for more than a month. I called Adobe Support the other day, that escalating the issue to the BIE team, who sent an automatic e-mail response that I was here in 24 hours, which was a week ago.

    These issues in IBE makes null and void, and I'll have to do all updates for customers of myself while apologizing constantly telling them that they would be able to make changes to their sites as themselves.

    Is there anyone on this forum who can attract the attention of the IBE team? Please note - I have tried all the normal channels.

    Thank you.

    This is a known bug and there is a current fix. Basically what is happening, it's there are two changes taking place simultaneously: 1) addition of text in a text frame and 2.) adding a link. The solution for all those who faced this problem is to add your text, click outside the text frame, click inside and add your link to the text (to break in two separate actions).

    Update (October 11, 2016): this issue has been resolved by the release of today. Adding hyperlinks to the new text should now work the first time.

  • Cannot create the spatial index

    It's a little bit of the puzzle for me this one, I made this little time on different system and I do not understand why it's here

    Oracle 11.1.0.7 Windows 64-bit

    We have simple following table:

    CREATE TABLE DASHBOARD. DSGEOEXCEPTION
    (
    GEOIDE NUMBER NOT NULL,
    ZORDER INTEGER DEFAULT 0 NOT NULL.
    HOUSENO VARCHAR2 (100),
    STREET VARCHAR2 (100),
    VARCHAR2 (100) SUBURBAN,.
    CITY VARCHAR2 (100),
    COUNTY OF VARCHAR2 (100),
    DESCRIPTION VARCHAR2 (200),
    MDSYS FORM. SDO_GEOMETRY
    )
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    NOMONITORING;

    ALTER TABLE DASH. (ADD) DSGEOEXCEPTION
    CONSTRAINT DSGEOEXCEPTION_PK
    KEY ELEMENTARY SCHOOL
    (GEOIDE)) ;



    Insert values (user_sdo_geom_metadata)
    "DASHBOARD. DSGEOEXCEPTION',.
    "FORM."
    MDSYS. () SDO_DIM_ARRAY
    MDSYS. SDO_DIM_ELEMENT ('LONGITUDE',-180, 180, 0.00005),
    MDSYS. SDO_DIM_ELEMENT ('LATITUDE',-90, 90, 0.00005)
    ),
    8307);

    until then, everything is good.

    I run the two sql suite to ensure that everything is fine

    Select * from USER_SDO_GEOM_METADATA;
    Dashboard. DSGEOEXCEPTION, shape, ((LONGITUDE,-180, 180, 5E-5), (LATITUDE, -90, 90, 5th-5),), 8307
    select * from mdsys.sdo_geom_metadata_table
    DASHBOARD, dashboard. DSGEOEXCEPTION, shape, ((LONGITUDE,-180, 180, 5E-5), (LATITUDE, -90, 90, 5th-5),), 8307
    select * from ALL_SDO_GEOM_METADATA;


    first 2 return one row as planned last returns nothing

    creating the index

    CREATE INDEXES DASH. DSGEOEXCEPTION_SIDX ON DASHBOARD. DSGEOEXCEPTION
    (FORM)
    INDEXTYPE IS MDSYS. SPATIAL_INDEX
    NOPARALLEL;

    or

    CREATE INDEXES DASH. DSGEOEXCEPTION_SIDX ON DASHBOARD. DSGEOEXCEPTION
    (FORM)
    INDEXTYPE IS MDSYS. SPATIAL_INDEX;


    fails with the error:

    ORA-29855: an error has occurred in the execution of routine ODCIINDEXCREATE
    ORA-13203: cannot read the notice USER_SDO_GEOM_METADATA
    ORA-13203: cannot read the notice USER_SDO_GEOM_METADATA
    ORA-06512: at the 'MDSYS. SDO_INDEX_METHOD_10I', line 10



    According to one of the posts, I run this

    ALTER session set current_schema = MDSYS;
    @$ORACLE_HOME/md/admin/prvtgmd.plb

    but no difference I can always create index


    Any suggestions?

    Please, try the following:

    Insert values (user_sdo_geom_metadata)
    "DSGEOEXCEPTION,"
    "FORM."
    MDSYS. () SDO_DIM_ARRAY
    MDSYS. SDO_DIM_ELEMENT ('LONGITUDE',-180, 180, 0.00005),
    MDSYS. SDO_DIM_ELEMENT ('LATITUDE',-90, 90, 0.00005)
    ),
    8307);

  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

Maybe you are looking for

  • Gmail stuck on loading.

    Hallo, Gmail wont fully load on Firefox. It stucks at 90% and stays there.I deleted cookies, install uninstall and I disabled 1 extensions I had.still does not load.Any idea guys? Thank you

  • How can I reinstall the favorite icon at the top of the home page?

    On the line from the top of my home page, the line that has the arrow download and homepage icon and icon menu to open, I used to have a star for bookmarking a page and icon for favorites. These two icons have disappeared. How do I get them back on t

  • 46YL863G - how to restore the YouTube application?

    Hello I have a problem with the lack of functionality of YouTube. As I bought my REGZA 46ty9175ch which is 46yl863g,I had problems with YouTube so I downgraded the firmware. After downgrade my YouTube icon is missing and the feature disappeared. I tr

  • I can't print because my Lexmark x 422 driver has a problem, where can I get this driver?

    I don't know why it's not working, but it does not leave my wireless printer works

  • virtual keyboard styles

    Hello Someone knows how you can affect the style of virtual keyboard which appears on a text input box? I have a box I want that people enter a time want so digital rather than the user easy paved style keyboard access are presented with the keyboard