CREATE OR REPLACE TABLE

Hi, i need to write a script that re-creates a table. Something similar to CREATE OR REPLACE VIEW. I came up with the following
DECLARE
   does_not_exist   EXCEPTION;
   PRAGMA EXCEPTION_INIT (does_not_exist, -942);
BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE foobar';
EXCEPTION
   WHEN does_not_exist
   THEN
      NULL;
END;
CREATE TABLE foobar (c1 INT);I wonder if there's an easier way. Is there?
TIA, Markus

Hi, Markus,
I don't know of anything simpler.
In SQL*Plus, you can do something that's about as complicated:
SET     PAGESIZSE     0
SPOOL     next_step.sql
SELECT     CASE
          WHEN  ( SELECT  1
                     FROM     user_tables
               WHERE     table_name     = 'FOOBAR'
          THEN  'DROP TABLE FOOBAR;'
          ELSE  'PROMPT  Table did not exist'
     END
FROM     dual;
SPOOL     OFF
@next_stepAll this supposes you really need something that doesn't raise an error.

Similar Messages

  • Creating a new table, to replace an old one

    Hi experts;
    I'm looking for an advice about what I'm going to do.
    This is the situation;
    I got a production table with more than 1,000,000,000 of records.
    the queries to this table are too slow, and I decided to create a new table, to replace this one.
    But my doubts are:
    How can I create a new table including the same structure as the old one, and with some data.
    I got this query:
    Create new_table as select * from old_table
    where trans_year = '2012';
    I know with this I got the structure, but what about indexes?
    My other doubt is, to replace the old one, just I drop it, and rename the new one?
    This table belong to an oracle 9i DB.
    Thanks for your comments.
    Al

    >
    How can I create a new table including the same structure as the old one, and with some data.
    I got this query:
    Create new_table as select * from old_table
    where trans_year = '2012';
    I know with this I got the structure, but what about indexes?
    My other doubt is, to replace the old one, just I drop it, and rename the new one?
    This table belong to an oracle 9i DB.
    >
    You could export the table metadata and then import it as a renamed table. That would keep the indexes, triggers, constraints.
    But for one table it may be easier to just recreate the indexes and other objects.
    For the query you may want to disable logging of the INSERT.
    Create table new_table NOLOGGING as select * from old_table where trans_year = '2012';
    -- set the table back to logging mode
    ALTER table new_table LOGGING;Then you can drop the old table (if you already have a backup of it) and rename the new one to the old name.
    The create will perform much better with NOLOGGING but because it is not logged you will not be able to recover the data from the log files.
    So you should take a backup afterward.

  • Problem in creating a nested table

    Hi i am working on Oracle 10g and cleint is sqlplus.
    Now while creating a nested table following error occured.
    This is the script for your reference.:
    CREATE OR REPLACE TYPE sec_pwd_hist_table
    AS
    TABLE OF sec_pwd_history_type
    index by binary_integer
    Warning: Type created with compilation errors.
    SQL> show error
    Errors for TYPE SEC_PWD_HIST_TABLE:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    3/1      PLS-00355: use of pl/sql table not allowed in this context
    Please help on this issue
    Regards,
    Vikas Kumar

    > but i want to know just one thing why its working when i am removing "INDEX BY binaty_integer"
    Vikas, I trust I answered that question when I said? :
    "Do not confuse the two. Do not attempt to use PL/SQL array struct definition syntax in the SQL engine for defining an ADT collection. Which is why I referred you to the manual to see how an ADT is defined in SQL."
    In other words, you are trying to apply a PL/SQL concept and PL/SQL syntax to a definition of a data type in SQL.
    SQL is not PL/SQL.
    SQL ADTs are not PL/SQL arrays/tables.
    It is not even a syntax issue - it is a basic concept issue. SQL does not support PL/SQL arrays/tables. Period.

  • Create or replace trigger

    hi i want to create trigger . when insert a row on table , it returns new value and old value . I have many tables and columns . i should to use :new.columntitle and :old.columntitle .Columntitle is refere to name of column in table . but sql developer is not accept it and show this error : BAD BIND VARIABLE 'NEW.COLUMNTITLE' .My code is this :
    Create or replace TRIGGER hr.departments_before_insert   
      before insert       on HR.departments 
       for each row
       DECLARE
          columnid number ;
         columnval number ;
         columntitle varchar2(4000);
         cursor c2 is
         select id,tableid from hr.columns where tableid = 1 ;
          tablesid number ;
          tablenames varchar2(4000);
          cursor c1 is
          select id , title from hr.tables where id = 1;
                    BEGIN
                    open c1;  
                           loop
                              fetch c1 into tablesid , tablenames;
                                  EXIT WHEN C1%NOTFOUND;    
                                   for rec in c2
                                            loop
                                                 select substr(title,instr(title,'.',-1,1)+1) into columntitle  from hr.columns where id = rec.id ;
                                                 dbms_output.put_line(:new.columntitle); -- in this line the eroor occured  : error = " bad bind variable 'new.columntitle' "
                                             end loop;
                             end loop;
                    close c1;    
                     end;
    -- in loop columntitle=deparment _id and department_name ; when i replace columntitle with department _id in :new , code is work ...
    thanks                                                                                                                                                         

    You have no choice but to specifically list the column names.
    If you really have "too many columns", that would tend to imply that you have improperly normalized your schema.  Perhaps you need to rethink the data model.
    If the real problem is that you want to generate similar triggers for a large number of different tables, you could write a PL/SQL block that generates the CREATE TRIGGER statement for each table and use EXECUTE IMMEDIATE to run those statements for each table.  Using dynamic SQL like this significantly complicates the complexity of building the trigger.  This may be balanced out, though, by the fact that you only have to write it once rather than writing separate triggers for each table.
    Justin

  • ORA-22913 while creating a QUEUE TABLE of a "Typed type"

    Hi guys:
    I'm trying to recreate an [AskTom's post|http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8760267539329], but with a single difference. My Oracle Type contains a field that is another Oracle Type and when I try to create a QUEUE_TABLE, I got the ORA-22913.
    Here are my steps:
    create or replace TYPE PODTL_TYPE AS OBJECT
    item varchar2(25),
    ref_item varchar2(25),
    physical_location_type varchar2(1),
    physical_location number(10),
    physical_qty_ordered number(12,4),
    unit_cost number(20,4),
    origin_country_id varchar2(3),
    supp_pack_size number(12,4),
    earliest_ship_date date,
    latest_ship_date date,
    pickup_loc varchar2(250),
    pickup_no varchar2(25),
    packing_method varchar2(6),
    round_lvl varchar2(6),
    door_ind varchar2(1),
    priority_level number(1),
    new_item varchar2(1),
    quarantine varchar2(1),
    rcvd_unit_qty number(12,4),
    tsf_po_link_id number(10),
    cost_source varchar2(4),
    est_in_stock_date date
    create or replace TYPE PODtl_coll as table of PODTL_TYPE;
    create or replace TYPE PODesc AS OBJECT
    doc_type varchar2(1),
    order_no varchar2(10),
    order_type varchar2(9),
    order_type_desc varchar2(250),
    dept number(4),
    dept_name varchar2(120),
    buyer number(4),
    buyer_name varchar2(120),
    supplier varchar2(10),
    promotion number(10),
    prom_desc varchar2(160),
    qc_ind varchar2(1),
    not_before_date date,
    not_after_date date,
    otb_eow_date date,
    earliest_ship_date date,
    latest_ship_date date,
    close_date date,
    terms varchar2(15),
    terms_code varchar2(50),
    freight_terms varchar2(30),
    cust_order varchar2(1),
    payment_method varchar2(6),
    payment_method_desc varchar2(40),
    backhaul_type varchar2(6),
    backhaul_type_desc varchar2(40),
    backhaul_allowance number(20,4),
    ship_method varchar2(6),
    ship_method_desc varchar2(40),
    purchase_type varchar2(6),
    purchase_type_desc varchar2(40),
    status varchar2(1),
    ship_pay_method varchar2(2),
    ship_pay_method_desc varchar2(40),
    fob_trans_res varchar2(2),
    fob_trans_res_code_desc varchar2(40),
    fob_trans_res_desc varchar2(250),
    fob_title_pass varchar2(2),
    fob_title_pass_code_desc varchar2(40),
    fob_title_pass_desc varchar2(250),
    vendor_order_no varchar2(15),
    exchange_rate number(20,10),
    factory varchar2(10),
    factory_desc varchar2(240),
    agent varchar2(10),
    agent_desc varchar2(240),
    discharge_port varchar2(5),
    discharge_port_desc varchar2(150),
    lading_port varchar2(5),
    lading_port_desc varchar2(150),
    bill_to_id varchar2(5),
    freight_contract_no varchar2(10),
    po_type varchar2(4),
    po_type_desc varchar2(120),
    pre_mark_ind varchar2(1),
    currency_code varchar2(3),
    contract_no number(6),
    pickup_loc varchar2(250),
    pickup_no varchar2(25),
    pickup_date date,
    app_datetime date,
    comment_desc varchar2(2000),
    PODtl PODtl_coll
    These are my 3 Oracle types. When I try to create the QUEUE TABLE:
    DBMS_AQADM.CREATE_QUEUE_TABLE(
    Queue_table => 'PODESC_QUEUE_TABLE',
    Queue_payload_type => 'PODesc',
    Multiple_consumers => TRUE);
    END;
    I got the following error:
    22913. 00000 - "must specify table name for nested table column or attribute"
    *Cause:    The storage clause is not specified for a nested table column
    or attribute.
    *Action:   Specify the nested table storage clause for the nested table
    column or attribute.
    How can I solve this?

    Here is the syntax used by Oracle in one of their internal tables.
    orabase> select dbms_metadata.get_ddl('TABLE', 'ORDERS_QUEUETABLE', 'IX') from dual;
    DBMS_METADATA.GET_DDL('TABLE','ORDERS_QUEUETABLE','IX')
      CREATE TABLE "IX"."ORDERS_QUEUETABLE"
       (    "Q_NAME" VARCHAR2(30),
            "MSGID" RAW(16),
            "CORRID" VARCHAR2(128),
            "PRIORITY" NUMBER,
            "STATE" NUMBER,
            "DELAY" TIMESTAMP (6),
            "EXPIRATION" NUMBER,
            "TIME_MANAGER_INFO" TIMESTAMP (6),
            "LOCAL_ORDER_NO" NUMBER,
            "CHAIN_NO" NUMBER,
            "CSCN" NUMBER,
            "DSCN" NUMBER,
            "ENQ_TIME" TIMESTAMP (6),
            "ENQ_UID" VARCHAR2(30),
            "ENQ_TID" VARCHAR2(30),
            "DEQ_TIME" TIMESTAMP (6),
            "DEQ_UID" VARCHAR2(30),
            "DEQ_TID" VARCHAR2(30),
            "RETRY_COUNT" NUMBER,
            "EXCEPTION_QSCHEMA" VARCHAR2(30),
            "EXCEPTION_QUEUE" VARCHAR2(30),
            "STEP_NO" NUMBER,
            "RECIPIENT_KEY" NUMBER,
            "DEQUEUE_MSGID" RAW(16),
            "SENDER_NAME" VARCHAR2(30),
            "SENDER_ADDRESS" VARCHAR2(1024),
            "SENDER_PROTOCOL" NUMBER,
            "USER_DATA" "IX"."ORDER_EVENT_TYP" ,   <---------------------- seems analogous to what you are trying to do
            "USER_PROP" "SYS"."ANYDATA" ,
             PRIMARY KEY ("MSGID")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOLOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "EXAMPLE"  ENABLE
       ) USAGE QUEUE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "EXAMPLE"
    OPAQUE TYPE "USER_PROP" STORE AS BASICFILE LOB (
      ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
      CACHE
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT))Spend some time looking in directories under $ORACLE_HOME and you may well find the DDL that built it.

  • I want to create an HTML table of img maps dynamically from DB retrieves...

    Hi,
    How do I build dynamic HTML code in a function and then populate a HTML region to render it.. (did I say that right?)
    I want to create an HTML table of img maps dynamically from DB retrieves...
    Thank you, Bill

    Vikas and Andy,
    Using Andy's code I'll go further...
    I want to create a function that returns HTML code that has been built dynamically.
    create or replace function "GET_CH_TABLE"
    return VARCHAR2
    is
    HTML_STRING VARCHAR2(2000); -- Create a string variable
    BEGIN
    HTML_STRING:= '<table align="center">' ||chr(10)||
    ' <tr>' ||chr(10)||
    ' <td> TEST ' ||chr(10)||
    ' /td>' ||chr(10)||
    ' /tr>' ||chr(10)||
    ' tr>' ||chr(10)||
    ' td>' ||chr(10)||
    ' a href=https:// ............etc. etc.. building the <TABLE> and <TD> cells having whatever I want... example.. changing the name of an image dependant on something else..
    return HTML_STRING; -- output the string to the region
    --also tried htp.p(HTML_STRING);
    END;
    =====================================
    Building the dynamic HTML is not my problem. It is how to get it into a region and to be read as HTML from a function call...
    I'd like the source of the region to be the returned HTML from a function call to GET_CH_TABLE();
    but it gives error:
    ORA-06550: line 1, column 7: PLS-00221: 'GET_CH_TABLE' is not a procedure or is undefined
    ORA-06550: line 1, column 7: PL/SQL: Statement ignored
    Debug:
    1: begin
    2: GET_CH_TABLE();
    3: end;
    I

  • Unable to create binary xmltype table

    HI Gentlemen,
    As I have serious difficulties with O-R storage, I now tried to create my ebm table in binary storage. The schemas were registered, no SQL-annotations at all.
    When I try to create the table, I always get an error message (see below). Does anybody know how to circumvent this?
    Thanks, regards
    Miklos HERBOLY
    SQL> @showkbvschemas
    SQL> /*
    SQL>   showKbvSchemas.sql
    SQL> */
    SQL> select any_path from resource_view where any_path like '%GKSADMIN%'
      2  /
    ANY_PATH                                                                       
    /sys/schemas/GKSADMIN                                                          
    /sys/schemas/GKSADMIN/EBM                                                      
    /sys/schemas/GKSADMIN/EBM/datentypen_V1.40.xsd                                 
    /sys/schemas/GKSADMIN/EBM/ehd_header_V1.40.xsd                                 
    /sys/schemas/GKSADMIN/EBM/ehd_root_V1.40.xsd                                   
    /sys/schemas/GKSADMIN/EBM/go_body_V1.30.xsd                                    
    /sys/schemas/GKSADMIN/EBM/go_header_V1.30.xsd                                  
    /sys/schemas/GKSADMIN/EBM/go_root_V1.30.xsd                                    
    /sys/schemas/GKSADMIN/EBM/keytabs_V1.40.xsd                                    
    17 Zeilen ausgewählt.
    SQL> /* eof */And now let us try to create the table:
    SQL> @crbinebm
    SQL> /* createBinaryEbmTable.sql */
    SQL> drop table ebm
      2  /
    drop table ebm
    FEHLER in Zeile 1:
    ORA-00942: Tabelle oder View nicht vorhanden
    SQL> CREATE TABLE ebm OF XMLType
      2    XMLTYPE STORE AS BINARY XML
      3    XMLSCHEMA          "EBM/go_root_V1.30.xsd"
      4    ELEMENT               "ehd"
      5    VIRTUAL COLUMNS
      6        (KV_COL AS (XMLCast(XMLQuery('xquery version "1.0"; (: :)
      7         declare namespace ehd="urn:ehd/001"; (: :)
      8         /ehd:ehd/ehd:header/ehd:provider/ehd:organization/ehd:id/@EX'
      9         PASSING OBJECT_VALUE RETURNING CONTENT)
    10         AS number)))
    11    PARTITION BY LIST (kv_COL)
    12        (
    13        PARTITION kv_Schleswig_Holstein VALUES ('01'),
    14        PARTITION kv_Hamburg VALUES ('02'),
    15        PARTITION kv_Bremen VALUES ('03'),
    16        PARTITION kv_Niedersachsen VALUES ('17'),
    17        PARTITION kv_Westfalen_Lippe VALUES ('20'),
    18        PARTITION kv_Nordrhein VALUES ('38'),
    19        PARTITION kv_Hessen VALUES ('46'),
    20        PARTITION kv_Rheinland_Pfalz VALUES ('51'),
    21        PARTITION kv_Baden_Wuerttemberg VALUES ('52'),
    22        PARTITION kv_Bayerns VALUES ('71'),
    23        PARTITION kv_Berlin VALUES ('72'),
    24        PARTITION kv_Saarland VALUES ('73'),
    25        PARTITION kbv VALUES ('74'),
    26        PARTITION kv_Mecklenburg_Vorpommern VALUES ('78'),
    27        PARTITION kv_Brandenburg VALUES ('83'),
    28        PARTITION kv_Sachsen_Anhalt VALUES ('88'),
    29        PARTITION kv_Thueringen VALUES ('93'),
    30        PARTITION kv_Sachsen VALUES ('98')
    31        )
    32  /
      XMLTYPE STORE AS BINARY XML
    FEHLER in Zeile 2:
    ORA-06502: PL/SQL: numerischer oder Wertefehler: Zeichenfolgenpuffer zu klein
    ORA-06512: in "XDB.DBMS_XDBUTIL_INT", Zeile 993
    SQL> /* EOF */
    SQL> spool offJust for your information, my table creation as pure relational, with one xmltype column based on the ebm schemas, was successful.

    HI Marco,
    Thank you very much. Yes, binary schema registration was OK. Then I visited the link you supplied and set up a createBinaryEbmTable script accordingly. Here are the results:
    SQL> @createBinaryEbmTable
    SQL> /* createBinaryEbmTable.sql */
    SQL> drop table ebm
      2  /
    Tabelle wurde gelöscht.
    SQL> CREATE TABLE ebm (
      2    kv               CHAR(2),
      3    xml_document          XMLType)
      4    SEGMENT CREATION IMMEDIATE
      5    NOCOMPRESS NOLOGGING
      6    TABLESPACE USERS
      7    XMLTYPE COLUMN xml_document STORE AS SECUREFILE BINARY XML
      8   (TABLESPACE USERS NOCOMPRESS  KEEP_DUPLICATES)
      9    XMLSCHEMA          "EBM/go_root_V1.30.xsd"
    10    ELEMENT               "ehd"
    11    PARTITION BY LIST (kv)
    12        (
    13        PARTITION kv_Schleswig_Holstein VALUES ('01'),
    14        PARTITION kv_Hamburg VALUES ('02'),
    15        PARTITION kv_Bremen VALUES ('03'),
    16        PARTITION kv_Niedersachsen VALUES ('17'),
    17        PARTITION kv_Westfalen_Lippe VALUES ('20'),
    18        PARTITION kv_Nordrhein VALUES ('38'),
    19        PARTITION kv_Hessen VALUES ('46'),
    20        PARTITION kv_Rheinland_Pfalz VALUES ('51'),
    21        PARTITION kv_Baden_Wuerttemberg VALUES ('52'),
    22        PARTITION kv_Bayerns VALUES ('71'),
    23        PARTITION kv_Berlin VALUES ('72'),
    24        PARTITION kv_Saarland VALUES ('73'),
    25        PARTITION kbv VALUES ('74'),
    26        PARTITION kv_Mecklenburg_Vorpommern VALUES ('78'),
    27        PARTITION kv_Brandenburg VALUES ('83'),
    28        PARTITION kv_Sachsen_Anhalt VALUES ('88'),
    29        PARTITION kv_Thueringen VALUES ('93'),
    30        PARTITION kv_Sachsen VALUES ('98')
    31        )
    32  /
    Tabelle wurde erstellt.
    SQL> /* EOF */
    SQL> @loadxmlfileascolumn_Int
    SQL> /* loadXmlFileAsColumn_INT.sql - interactive version */
    SQL> @@sourcedir
    SQL> /*
    SQL>   set SOURCE_DIR for XML
    SQL>   Parameter 1: source directory
    SQL> */
    SQL>
    SQL> create or replace directory SOURCE_DIR as '&source_directory'
      2  /
    Geben Sie einen Wert für source_directory ein: c:\gks\kbv\h\ebm
    alt   1: create or replace directory SOURCE_DIR as '&source_directory'
    neu   1: create or replace directory SOURCE_DIR as 'c:\gks\kbv\h\ebm'
    Verzeichnis wurde erstellt.
    SQL>
    SQL> declare
      2    InstanceDocument varchar2(4000);
      3  begin
      4    INSERT INTO &XMLTypeTable
      5        VALUES (&id, XMLType(bfilename('SOURCE_DIR', '&InstanceDocument'),
      6             nls_charset_id('ISO-8859-1')));
      7  end;
      8  /
    Geben Sie einen Wert für xmltypetable ein: ebm
    alt   4:   INSERT INTO &XMLTypeTable
    neu   4:   INSERT INTO ebm
    Geben Sie einen Wert für id ein: 46
    Geben Sie einen Wert für instancedocument ein: test46.xml
    alt   5:     VALUES (&id, XMLType(bfilename('SOURCE_DIR', '&InstanceDocument'),
    neu   5:     VALUES (46, XMLType(bfilename('SOURCE_DIR', 'test46.xml'),
    declare
    FEHLER in Zeile 1:
    ORA-31061: XDB-Fehler: XML event error
    ORA-19202: Fehler bei XML-Verarbeitung 
    LSX-00333: Message 333 not found; No message file for product=XDK, facility=LSX
    aufgetreten
    ORA-06512: in Zeile 4
    SQL> spool offAs you see, yet another issue: I modified the pattern in the corresponding scheme to grow in length step-by-step, and it did not like this as well. And, I really do not know, why no messages are found: my XDK_HOME points to %ORACLE_HOME%\XDK where the mesg files are, but som other parts of the XDK kit is under %ORACLE_HOM%\LIB. Any idea?
    Thanks, regards
    Miklos

  • Oracle VIEW created on SAP table

    Hi All,
    I've Oracle 10g. I've a view in it on an SAP table using DB link.
    I started getting error ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind when this view is fetched using FOR loop. On investigation, I found that there is a column which when VIEW is described shows datatype as VARCHAR2(10) but it actually has some records with length more than 10.
    When I modified PL/SQL block and modified this query by adding SUBSTR on the column to get just 10 chars, it worked.
    I suspect that this SAP table might have been recently altered to increase columns length i.e. altered after VIEW was created on it. Here, my question is that will I need to recreate this view? As usually when a view is created on an Oracle table, it automatically inherits table column's data types. even when a table column is altered after view is created.
    Thanks in advance.

    Hi Chintan,
    Why can't you Query the SAP table and checking the length of the column ?
    I think the error is now in the view. I think the problem is with the code. Hope you might
    have declared a variable which does not fit the size of the value you are assigning.
    This may be the cause too when you take the substr function you are not getting errors.
    Can you Please the code ??
    And,
    If I am Clear,
    When you create a view from SAP table, we just issue,
    CREATE OR REPLACE VIEW sp_view
    AS
       SELECT *
         FROM sapprd.marm@sap;And, the view is created based onthe base Table. So the datatype is inherited, for VARCHAR and NUMBER datatype.
    And, the TIMESTAMP in SAP is to VARCHAR2 type in oracle.
    Thanks,
    Shankar

  • Can we create global internal table in data dictionary

    help me
    i want to know whether we can create global internal tables in data dictionary

    Hi Swathi,
    The whole concept of internal table is to manipulate the data at runtime.
    This replaces the concept of two dimentional array in other languages.
    The power of internal tables is it gets lakhs of records at runtime. I mean it can accomodate lots of records at runtime.
    So you can create a table type in DDIC and use it to declare your internal table.
    Yes, You can create global internal tables for function modules.
    By declaring the internal table in top include you can use this internal table all the function modules of that function group. So if one function module is filling the data another can use it as it is stored globally.
    Hope this answers your curiosity.
    Award points if useful else getback.
    Aleem.

  • Can we create scroll bar Table in ADE?

    Hi All,
    Can we create scroll bar Table in ADE. Please refer the enclosed attachment Table.JPG.
    We used the following CSS property, which is displaying the scroll bar table in HTML but not in ADE.
    #table_data {width:400px; overflow:auto; }
    Please Suggest.
    Regards,
    Jaffar

    Hi Swathi,
    The whole concept of internal table is to manipulate the data at runtime.
    This replaces the concept of two dimentional array in other languages.
    The power of internal tables is it gets lakhs of records at runtime. I mean it can accomodate lots of records at runtime.
    So you can create a table type in DDIC and use it to declare your internal table.
    Yes, You can create global internal tables for function modules.
    By declaring the internal table in top include you can use this internal table all the function modules of that function group. So if one function module is filling the data another can use it as it is stored globally.
    Hope this answers your curiosity.
    Award points if useful else getback.
    Aleem.

  • How to create a type table in designer 9i

    Hi
    In our company we use designer 9i. I want to create a type table using designer. Is it possible? I have a requirement where i need to create a type table and use in creating a view through designer.
    Create or replace type varchar2_ntt as table of varchar2(4000);
    [\pre]
    Please suggest.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi
    Here I am giving the step by step process.
    1. select the container in which container you are going to create the type.
    2.Go to tools then design editor and expand the container. There you will find oracle collection types. there we have to create a new one by clicking the + button on the left side.
    3. Give the name of the new collection type.
    4. And in the collection of tab, let it be scalar, give the scalar data type,and the size and click finish.
    5. then right click on that object and give generate. there you select theDDL files only and the give the path where the scripts have to go.
    This the process.
    Thanks,
    raju

  • Create Or Replace Function Error

    Hello,
    I'm doing text mining using Oracle SQL Developer: ODMiner.. I imported the data "WEBLOG" into a table.. This weblog data consist of users activity, date, time, url, etc. The first step I took was to use a function to transform date and time that I have in the data table, into a number representing the 40 mins since 01-01-1990. I did this by dividing it by 2400 (seconds in 40 mins). The main purpose is to have a time frame for the sessions.
    I used the following code,
    CREATE OR REPLACE FUNCTION ssnDate(
    DATE IN VARCHAR2 DEFAULT 03-01-18,
    TIME IN VARCHAR2
    ) RETURN NUMBER
    AS
    BEGIN
    RETURN TRUNC((to_date(DATE||' '||TIME, 'DD-MM-YY HH:MM:SS')- to_date('01-JAN-1990','DD-MON-YYYY')) * (86400/2400);
    END ssnDate;
    This was what appeared in the log after running the statement,
    FUNCTION ssnDate compiled
    Warning: execution completed with warning
    After this, I tried to create a VIEW to transform the DATE and TIME with the ssnDate that was created earlier on, and concatenate the CS_URI_STEM (which is the resource accessed), and CS_URI_QUERY (which is the the query, if any, the client was trying to perform)into a new field called WEB_LINK.
    This is the code used,
    CREATE OR REPLACE VIEW WEBLOG_VIEWS("C_IP", "WEB_LINK", "CS_USER_AGENT", "SESSION")
    AS
    SELECT ssnDate(LOG_DATE, LOG_TIME) AS 'SESSION',
    C_IP,
    CS_USER_AGENT,
    (CS_URI_STEM||'?'||CS_URI_QUERY) AS WEB_LINK
    FROM WEBLOG;
    Now from this I got the following error..
    Error starting at line 1 in command:
    CREATE OR REPLACE VIEW WEBLOG_VIEWS("C_IP", "WEB_LINK", "CS_USER_AGENT", "SESSION")
    AS
    SELECT ssnDate(LOG_DATE, LOG_TIME) AS 'SESSION',
    C_IP,
    CS_USER_AGENT,
    (CS_URI_STEM||'?'||CS_URI_QUERY) AS WEB_LINK
    FROM WEBLOG
    Error at Command Line:3 Column:38
    Error report:
    SQL Error: ORA-00923: FROM keyword not found where expected
    00923. 00000 - "FROM keyword not found where expected"
    *Cause:
    *Action:
    I don't get where I'm going wrong with this.. This is the data preparation stage which requires me to prep the data before applying modeling techniques or algorithms.. The next step would be grouping the data, based on the session time, ip and the user agent of each session along with the web_links fields visited by the user in that session.
    I would really be grateful for any inputs on where I'm going wrong and any solutions for that!

    Ok, not sure I really understand, but I posted the query and this is the output I got..
    ORA-31603: object "WEBLOG" of type TABLE not found in schema "WEBLOG_TABLE_OWNER_NAME"
    ORA-06512: at "SYS.DBMS_METADATA", line 2625
    ORA-06512: at "SYS.DBMS_METADATA", line 2668
    ORA-06512: at "SYS.DBMS_METADATA", line 2983
    ORA-06512: at "SYS.DBMS_METADATA", line 3897
    ORA-06512: at "SYS.DBMS_METADATA", line 5678
    ORA-06512: at line 1
    31603. 00000 - "object \"%s\" of type %s not found in schema \"%s\""
    *Cause:    The specified object was not found in the database.
    *Action:   Correct the object specification and try the call again.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • CREATE OR REPLACE PROCEDURE return data like SELECT statement

    "SELECT * FROM SEARCH_KEYWORD" is successfully done and return the data of the tables. Now, I want to run that on server side using PROCEDURE.
    I successfully executed the below scripts. Please teach me how to call the sp_test procedure. OR if you have other way or maybe my scripts are wrong.
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
         TYPE RCT1 IS REF CURSOR;
         TRANCOUNT INTEGER := 0;
         IDENTITY INTEGER;
    END;
    CREATE OR REPLACE PROCEDURE LPG.sp_test
         RCT1 IN OUT      GLOBALPKG.RCT1
    AS
    BEGIN
         OPEN RCT1 FOR
         SELECT *
         FROM SEARCH_KEYWORD;
    END;
    Here is my table definition:
    CREATE TABLE LPG.SEARCH_KEYWORD
    FRACTION VARCHAR2(50),
    KEYWORD VARCHAR2(50),
    PURPOSE VARCHAR2(50),
    REMARKS VARCHAR2(50),
    DATE_INSERTED DATE DEFAULT sysdate
    PCTFREE 10
    PCTUSED 40
    MAXTRANS 255
    TABLESPACE SYSTEM
    STORAGE(INITIAL 64K MINEXTENTS 1 MAXEXTENTS 2147483645 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    NOCACHE
    LOGGING
    Eros
    Japan

    Wrong forum. You should ask this question in the SQL and PL/SQL forum.
    Couple of comments though. Oracle is not SQL-Server. So calling a procedure that returns a ref cursor is different from a T-SQL macro procedure that functions like a view.
    Also, there is no need to use the SQL-Server standard (and silly one at that) of prefixing stored procedures using the text "sp_". In fact, the whole concept of Hungarian-like notation is something of the past and has no place in today's paradigm of software engineering.
    As for calling a a proc that returns a ref cursor, from SQL*Plus it will look as follows:
    SQL> var c refcursor
    SQL>
    SQL> exec LPG.sp_test( :c )
    SQL> print c
    Ref cursor needs to be supported by the client language you use to make this call to Oracle.

  • Action of trigger to create records in table - how enusre parent commits

    Hi,
    Using oracle 11.2.0.3 and wish to do the following.
    Have trigger on table a on database a.
    When a record is inserted into table a a record should be written first to table1 on database b , committed then a record written to table2 on database b
    as table2 has fk dependency on table 1.
    How can we best achieve this.
    Getting problems with the commit inside the trigger have tried pragma autonous transaction as well.
    Get ora-02064 distributed transaction not supported when use the following code
    create or replace trigger por_TRG_POP_IKNOW_MULTIPLE2
    after INSERT OR UPDATE or delete   on por_MULTIPLE
    for each row
    -- tO ENSURE I-KNOW KEPT UP-TO-DATE WITH HOMIS MULTIPLE
    -- delib not delet form i-know as if has been used by customer cannot delete
    -- due to referential inetgrity constraints in i-know
    -- Note parent_num updated on IKW via support.maintain_latest_dim_version.update_multiple until
    -- When IKW becomes master of multiple info, this trigger can be removed
    -- and support.maintain_latest_dim_version.update_multiple removed
    declare
      PRAGMA AUTONOMOUS_TRANSACTION;
    v_dml_type varchar2(1);
    begin
       IF INSERTING OR UPDATING
       THEN
    MERGE INTO [email protected] a
          USING
           select
           :new.MULT_LINK_MULTIPLE_CODE MULT_LINK_MULTIPLE_num
           multiple2.mult_name
           from dual, por_multiple multiple2
           where :new.MULT_LINK_MULTIPLE_CODE = multiple2.mult_multiple_code
           ) b
        on
           b.mult_link_multiple_NUM = a.mgrp_NUM
    --when matched THEN update set
    --      a.MGRP_NUM b.mult_link_multiple_num,
    --      MGRP_DESCRIPTION = (select mult_name from por_multiple
      --                         where mult_code = mult_link_multiple_code
    when not matched
    then insert
    a.MGRP_NUM,
    a.MGRP_DESCRIPTION
    values
           b.mult_link_multiple_num,
           b.mult_name
    end if;
    commit;
    EXCEPTION
         WHEN OTHERS THEN
            RAISE_APPLICATION_ERROR(-20010,'Error when writing to i-know multiple '||SQLERRM||' '||SQLCODE);
    END por_TRG_POP_IKNOW_MULTIPLE2;Thanks
    Edited by: user5716448 on 14-May-2013 06:20

    Hi,
    Get ORA-02064 when try as suggested - distributed transaction not supported.
    Thanks
    create or replace trigger por_TRG_POP_IKNOW_MULTIPLE
    after INSERT OR UPDATE or delete   on por_MULTIPLE
    for each row
    -- tO ENSURE I-KNOW KEPT UP-TO-DATE WITH HOMIS MULTIPLE
    -- delib not delet form i-know as if has been used by customer cannot delete
    -- due to referential inetgrity constraints in i-know
    -- Note parent_num updated on IKW via support.maintain_latest_dim_version.update_multiple until
    -- When IKW becomes master of multiple info, this trigger can be removed
    -- and support.maintain_latest_dim_version.update_multiple removed
    declare
    v_dml_type varchar2(1);
    --pragma autonomous_transaction;
    begin
       IF INSERTING OR UPDATING
       THEN
    MERGE INTO [email protected] a
          USING
           select
           :new.MULT_LINK_MULTIPLE_CODE MULT_LINK_MULTIPLE_num
           from dual
           ) b
        on
           b.mult_link_multiple_NUM = a.mgrp_NUM
    --when matched THEN update set
    --      a.MGRP_NUM =b.mult_link_multiple_nuM
    when not matched
    then insert
    a.MGRP_NUM
    values
           b.mult_link_multiple_num
          MERGE INTO [email protected] a
          USING
           select
           :NEW.MULT_ANMW_MULTIPLE_CODE MULT_ANMW_MULTIPLE_CODE,
           :new.MULT_AUTH_REQUIRED MULT_AUTH_REQUIRED,
           :new.MULT_JMW_MULTIPLE_TYPE_CODE MULT_JMW_MULTIPLE_TYPE_CODE,
           :new.MULT_LINK_MULTIPLE_CODE MULT_LINK_MULTIPLE_num,
           :new.MULT_MULTIPLE_CODE MULT_MULTIPLE_NUM,
           :new.MULT_NAME MULT_NAME,
           :new.MULT_PROM_AUTH_REQUIRED MULT_PROM_AUTH_REQUIRED,
           :new.MULT_SELECTED_MULTIPLE MULT_SELECTED_MULTIPLE,
               'Y' MULT_active_flag,
           nvl(:new.MULT_JMW_MULTIPLE_TYPE_CODE, 0) MULT_CHANNEL_NUM,
           :new.MULT_LINK_MULTIPLE_CODE MULT_PARENT_NUM -- added 14/05/13
           from dual
           ) b
        on
           a.mult_multiple_NUM = b.MULT_MULTIPLE_NUM
    when matched THEN update set
           A.MULT_ANMW_MULTIPLE_CODE = B.MULT_ANMW_MULTIPLE_CODE ,
           A.MULT_AUTH_REQUIRED = B.MULT_AUTH_REQUIRED,
           A.MULT_JMW_MULTIPLE_TYPE_CODE = B.MULT_JMW_MULTIPLE_TYPE_CODE ,
           A.MULT_LINK_MULTIPLE_num = B.MULT_LINK_MULTIPLE_num,
           A.MULT_NAME =B.MULT_NAME,
           A.MULT_PROM_AUTH_REQUIRED=B.MULT_PROM_AUTH_REQUIRED,
           A.MULT_SELECTED_MULTIPLe=B.MULT_SELECTED_MULTIPLE,
               A.MULT_ACTIVE_FLAG = B.MULT_ACTIVE_FLAG,
           A.MULT_CHANNEL_NUM= B.MULT_CHANNEL_NUM,
           a.mult_parent_num = B.MULT_LINK_MULTIPLE_num
    when not matched
    then insert
    A.MULT_ANMW_MULTIPLE_CODE,
           A.MULT_AUTH_REQUIRED,
           A.MULT_JMW_MULTIPLE_TYPE_CODE,
           A.MULT_LINK_MULTIPLE_NUM,
           A.MULT_MULTIPLE_NUM,
           A.MULT_NAME,
           a.MULT_PROM_AUTH_REQUIRED,
           a.MULT_SELECTED_MULTIPLE,
           -- NEW FIELDS ON I-KNOW
           a.MULT_ACTIVE_FLAG,
            a.MULT_CHANNEL_NUM,
            a.MULT_PARENT_NUM
    values
           b.MULT_ANMW_MULTIPLE_CODE,
           b.MULT_AUTH_REQUIRED,
           b.MULT_JMW_MULTIPLE_TYPE_CODE,
           b.MULT_LINK_MULTIPLE_NUM,
           b.MULT_MULTIPLE_NUM,
           b.MULT_NAME,
           b.MULT_PROM_AUTH_REQUIRED,
           b.MULT_SELECTED_MULTIPLE,
           -- NEW FIELDS ON I-KNOW
           b.MULT_ACTIVE_FLAG,
            b.MULT_CHANNEL_NUM,
            b.MULT_LINK_MULTIPLE_NUM
    else
         update [email protected] p
         set  mult_active_flag = 'N'
         where  p.mult_multiple_num = :old.mult_multiple_code;
    END IF;
    if inserting
    then
       v_dml_type := 'I';
    else
      if updating
      then  
         v_dml_type := 'U';
      else
         v_dml_type := 'D' ; 
      end if;  
    end if;
    /*INSERT INTO IKNOW_AUDIT_MULTIPLE_CHANGES
    MULT_MULTIPLE_CODE,
    MULT_NAME,
    MULT_SELECTED_MULTIPLE,
    MULT_ANMW_MULTIPLE_CODE,
    MULT_LINK_MULTIPLE_CODE,
    MULT_JMW_MULTIPLE_TYPE_CODE,
    MULT_AUTH_REQUIRED,
    MULT_PROM_AUTH_REQUIRED,
    dml_type,
    DATE_ACTIONED,
    MULT_PARENT_NUM
    values
           :new.MULT_MULTIPLE_CODE ,
           :new.MULT_NAME,
           :new.MULT_SELECTED_MULTIPLE,
           :NEW.MULT_ANMW_MULTIPLE_CODE,
           :new.MULT_LINK_MULTIPLE_CODE,
           :new.MULT_JMW_MULTIPLE_TYPE_CODE ,
           :new.MULT_AUTH_REQUIRED ,
           :new.MULT_PROM_AUTH_REQUIRED,
           v_dml_type ,
           sysdate,
           :new.MULT_LINK_MULTIPLE_CODE
    EXCEPTION
         WHEN OTHERS THEN
            RAISE_APPLICATION_ERROR(-20010,'Error when writing to i-know multiple '||SQLERRM||' '||SQLCODE);
    END por_TRG_POP_IKNOW_MULTIPLE;

  • End-user experience during CREATE OR REPLACE TRIGGER

    Is CREATE OR REPLACE TRIGGER intended for you to be able to update a trigger in production while users are actively using a that table's data?
    Just wondering how it behaves. People currently in the middle of an event will use the old trigger, while new requests will use the new one?
    Thanks
    Chuck

    Actually, this one kind of surprised me. I tried:
    SESSION1 > DESC t
    Name                                      Null?    Type
    ID                                                 NUMBER
    DESCR                                              VARCHAR2(10)
    SESSION1 > CREATE TRIGGER t_bi
      2  BEFORE INSERT OR UPDATE ON t
      3  FOR EACH ROW
      4  BEGIN
      5     :new.descr := UPPER(:new.descr);
      6* END;
    Trigger created.Then, in anothe session I did:
    SESSION2 > INSERT INTO t VALUES (1, 'One');
    1 row created.Then in the first session:
    SESSION1 > CREATE OR REPLACE TRIGGER t_bi
      2  BEFORE INSERT OR UPDATE ON t
      3  FOR EACH ROW
      4  BEGIN
      5     :new.descr := LOWER(:new.descr);
      6* END;
    Trigger created.
    Just to prove no commit happened
    SESSION1 >SELECT * FROM t;
    no rows selectedI was expecting to see
    ORA-00054: resource busy and acquire with NOWAIT specified
    or something similar. So in session 2 I did:
    SESSION2 > COMMIT;
    Commit complete.
    SESSION2 > SELECT * FROM t;
            ID DESCR
             1 ONE
    SESSION2 > INSERT INTO t VALUES(2, 'Two');
    1 row created.
    SESSION2 > SELECT * FROM t;
            ID DESCR
             1 ONE
             2 twoSo, the new trigger is working. Now change it again:
    SESSION1 > CREATE OR REPLACE TRIGGER t_bi
      2  BEFORE INSERT OR UPDATE ON t
      3  FOR EACH ROW
      4  BEGIN
      5     :new.descr := UPPER(:new.descr);
      6  END;
      7  /
    Trigger created.and back to session 2
    SESSION2 > INSERT INTO t VALUES (3, 'Three');
    1 row created.
    SESSION2 > SELECT * FROM t;
            ID DESCR
             1 ONE
             2 two
             3 THREESo, it looks like whichever trigger is current at the time of the insertion or updation seems to control what gets in the database.
    John

Maybe you are looking for