Create the table in select * from the other table

DB: 11.2.0.2

How to create a table with structure only not empty the data that we do not generally create table in select * from... But the command will pull the data also. How to create without data?

create table foo
in select * bar
where 1 = 0

Tags: Database

Similar Questions

  • To create an interactive report in the apex by selecting from multiple tables

    Hi, I am creating an interactive report by selecting from multiple tables.

    SELECT w.FIRST_NAME as name, w.SURNAME as name, i.ROAD Road, i.DATE_OF_INC as DATE_OF_INC, S.STATEMENT as a STATEMENT OF Declaration

    JOIN THE

    WITNESS w

    ON w.witness_id = s.FK1_WITNESS_ID

    JOIN THE

    Incident I have

    WE

    i.incident_no = w.FK1_INCIDENT_NO

    JOIN THE

    user_station ps

    ON ps.station_id = i.nearest_station_id

    JOIN THE

    the user in.

    WE

    in. STATION_ID = ps.station_id

    WHERE po.officer_id = 1

    by I continue to encounter this error "the report query requires a unique key to identify each row. The supplied key cannot be used for this query. Please change the report attributes to define a unique key column. "ORA-01445: cannot select ROWID from where sample, a join without key preserved table view '

    So I googled around and found that in the attibutres tables report, I need to change the "LINK" COLUMN so first, I changed "Link to custom target", but the report is so I changed it to "Exclude link Clolumn" again, the report didn't report and I STILL got a blank page with only the tabs.

    I wonder you can not create a report by selecting from multiple tables?

    If you can please I need your help.

    Thank you

    You can, but in this case, it might be easier to build your report tables that are joined Oracle views and then build your report out of the newly built sight...

    Or wrap a selection around your selection with joins, and then make the where clause on the external selection...

    Thank you

    Tony Miller
    Software LuvMuffin
    Ruckersville, WILL

  • problem in creating the xml section group

    I created the Group xml section with a few sections defined in the field. Now my attributes are repeated with root different nodes.so I put braces for differentiation and created the context index.
    Drop index abc_indexes_idx;

    Start
    ctx_ddl.remove_section ('xyz_xml_group', 'abLName');
    ctx_ddl.remove_section ('xyz_xml_group', 'abFName');
    ctx_ddl.remove_section ('xyz_xml_group', 'cdLName');
    ctx_ddl.remove_section ('xyz_xml_group', 'cdFName');
    ctx_ddl.remove_section ('xyz_xml_group', 'efLName');
    ctx_ddl.remove_section ('xyz_xml_group', 'efFName');
    ctx_ddl.remove_section ('xyz_xml_group', 'ghLName');
    ctx_ddl.remove_section ('xyz_xml_group', 'ghFName');
    end;
    Start
    ctx_ddl.drop_section_group ('xyz_xml_group');
    end;
    Start
    ctx_ddl.drop_preference ('xyz_wildcard_pref1');
    end;
    Start
    ctx_ddl.drop_preference ('xyz_lexer_pref1');
    end;
    Start
    ctx_ddl.drop_preference ('STEM_FUZZY_PREF');
    end;
    Start
    ctx_ddl.create_section_group ('xyz_xml_group', 'XML_SECTION_GROUP');
    ctx_ddl.add_field_section ('xyz_xml_group', 'abLName','IncidentSubject(PersonGivenName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'abFName','IncidentSubject(PersonSurName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'cdLName','ActivityVictim(PersonGivenName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'cdFName','ActivityVictim(PersonSurName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'efLName','ActivityComplainantPerson(PersonGivenName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'efFName','ActivityComplainantPerson(PersonSurName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'ghLName','ActivityWitness(PersonGivenName');)
    ctx_ddl.add_field_section ('xyz_xml_group', 'ghFName','ActivityWitness(PersonSurName');)
    end;
    Start
    ctx_ddl.create_preference ('STEM_FUZZY_PREF', 'BASIC_WORDLIST');
    ctx_ddl.set_attribute ('STEM_FUZZY_PREF', 'SUBSTRING_INDEX', 'TRUE');
    end;
    Start
    ctx_ddl.set_attribute ('STEM_FUZZY_PREF', 'PREFIX_INDEX', 'YES');
    end;
    Start
    ctx_ddl.create_preference ('njdex_lexer_pref1', 'BASIC_LEXER');
    ctx_ddl.set_attribute('STEM_FUZZY_PREF','WILDCARD_MAXTERMS','15000');
    end;

    Drop index xyz_indexes_idx
    create index xyz_indexes_idx on xyz_INDEXES (abc column) indextype is ctxsys.context settings
    ("datastore ctxsys.direct_datastore wordlist STEM_FUZZY_PREF FILTER ctxsys.null_filter lexer xyz_lexer_pref1
    Sync (on commit) GROUP of SECTIONS xyz_xml_group MEMORY 500 M ");"

    My XML document is stored in a column of abc whichi and it is of type xmltype

    <? XML version = "1.0" encoding = "utf-8"? >
    < ab: IncidentReportGroup xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:j = "http://www.it.ojp.gov/jxdm/3.0.3" xmlns:ext = "http://xml.abc.com/jxdm/3.0.3/extension" xmlns:ab = "http://xml.abc.com/jxdm/3.0.3" >
    < ab: IncidentReport >

    < ext:IncidentSubject >
    < j: PersonName >
    < j: PersonGivenName > CBA < / j: PersonGivenName >
    < j: PersonMiddleName / >
    XYZ < j: PersonSurName > < / j: PersonSurName >
    < j: PersonSuffixName / >
    < j: PersonFullName > abc, xyz < / j: PersonFullName >
    < / j: PersonName >
    < / ext:IncidentSubject >
    < ext:ActivityComplainantPerson >
    < j: PersonName >
    < j: PersonGivenName > CBA < / j: PersonGivenName >
    < j: PersonMiddleName / >
    XYZ < j: PersonSurName > < / j: PersonSurName >
    < j: PersonSuffixName / >
    < j: PersonFullName > abc, xyz < / j: PersonFullName >
    < / j: PersonName >
    < / ext:ActivityComplainantPerson >
    < ext:ActivityWitness >
    < j: PersonName >
    < j: PersonGivenName > CBA < / j: PersonGivenName >
    < j: PersonMiddleName / >
    XYZ < j: PersonSurName > < / j: PersonSurName >
    < j: PersonSuffixName / >
    < j: PersonFullName > abc, xyz < / j: PersonFullName >
    < / j: PersonName >
    < / ext:ActivityWitness >

    < ext:ActivityVictim >
    < j: PersonName >
    < j: PersonGivenName > CBA < / j: PersonGivenName >
    < j: PersonMiddleName / >
    XYZ < j: PersonSurName > < / j: PersonSurName >
    < j: PersonSuffixName / >
    < j: PersonFullName > abc, xyz < / j: PersonFullName >
    < / j: PersonName >

    < / ext:ActivityVictim >
    < ext:ActivityWitness >
    < / ab: IncidentReport >
    < / ab: IncidentReportGroup >


    now when I try to run the query

    Select * from xyz_indexes where contains (xyzcolumn,'(LORI WITHIN abLName))
    (& ("BELAND" WITHIN abFName)') > 0


    He doesn't do anything.

    Can someone provide me with assistance in this regard.

    I think that what you probably need is xml_path_group and inpath, instead of xml_section_group and breast. Please see the demo below.

    SCOTT@orcl_11g> SET DEFINE OFF
    SCOTT@orcl_11g> begin
      2    ctx_ddl.drop_section_group('xyz_xml_group');
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> begin
      2    ctx_ddl.drop_preference('xyz_lexer_pref1');
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> begin
      2    ctx_ddl.drop_preference('STEM_FUZZY_PREF');
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> begin
      2    ctx_ddl.create_section_group('xyz_xml_group','PATH_SECTION_GROUP');
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> begin
      2    ctx_ddl.create_preference('STEM_FUZZY_PREF','BASIC_WORDLIST');
      3    ctx_ddl.set_attribute('STEM_FUZZY_PREF','SUBSTRING_INDEX','TRUE');
      4  end;
      5  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> begin
      2    ctx_ddl.set_attribute('STEM_FUZZY_PREF','PREFIX_INDEX','YES');
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> begin
      2    ctx_ddl.create_preference('xyz_lexer_pref1','BASIC_LEXER');
      3    ctx_ddl.set_attribute('STEM_FUZZY_PREF','WILDCARD_MAXTERMS','15000');
      4  end;
      5  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11g> drop index xyz_indexes_idx
      2  /
    
    Index dropped.
    
    SCOTT@orcl_11g> DROP TABLE xyz_indexes
      2  /
    
    Table dropped.
    
    SCOTT@orcl_11g> CREATE TABLE xyz_indexes
      2    (xyzcolumn  XMLTYPE)
      3  /
    
    Table created.
    
    SCOTT@orcl_11g> INSERT INTO xyz_indexes VALUES
      2  (XMLTYPE (
      3  '
      4  
      5    
      6        
      7          
      8            LORI
      9            
     10            "BELAND"
     11            
     12            abc, xyz 
     13          
     14        
     15        
     16          
     17            abc
     18            
     19            xyz
     20            
     21            abc, xyz 
     22          
     23        
     24        
     25          
     26            abc
     27            
     28            xyz
     29            
     30            abc, xyz 
     31          
     32        
     33        
     34          
     35            abc
     36            
     37            xyz
     38            
     39            abc, xyz 
     40          
     41        
     42    
     43  '
     44  ))
     45  /
    
    1 row created.
    
    SCOTT@orcl_11g> create index xyz_indexes_idx on xyz_INDEXES(xyzcolumn) indextype is ctxsys.context parameters
      2  ('datastore ctxsys.direct_datastore wordlist STEM_FUZZY_PREF FILTER ctxsys.null_filter lexer xyz_lexer_pref1
      3  sync(on commit)SECTION GROUP xyz_xml_group MEMORY 500M ')
      4  /
    
    Index created.
    
    SCOTT@orcl_11g> select * from xyz_indexes
      2  where  contains
      3             (xyzcolumn,
      4              'LORI INPATH (//ext:IncidentSubject/j:PersonName/j:PersonGivenName) &
      5            "BELAND" INPATH (//ext:IncidentSubject/j:PersonName/j:PersonSurName)') > 0
      6  /
    
    XYZCOLUMN
    --------------------------------------------------------------------------------
    
    
      
        
          
            LORI
            
            "BELAND"
            
            abc, xyz 
          
        
        
          
            abc
            
            xyz
            
            abc, xyz 
          
        
        
          
            abc
            
            xyz
            
            abc, xyz 
          
        
        
          
            abc
            
            xyz
            
            abc, xyz 
          
        
      
    
    
    SCOTT@orcl_11g> 
    
  • How to create the database links

    Hello

    We have two databases on two servers differenet and we want both of the databases to be synchronized and application runs only on a single server.

    It is possible through links DB if yes then how.

    If a better solution than DB links is pl tell.

    Hello

    Edit the tnsmaes.ora file and add the entry to the database and verify the connection using tnsping .if connection is ok and then create a database link in oracle

    CREATE DATABASE LINK link_name - name of the link
    CONNECT username - user name
    IDENTIFIED BY password - password of the user
    With the HELP of "Database_sid" - name of the database

    Created database link

    Select * from owner.table_name @ link_name

  • missing parenthesis in insertion into separate lines select the table from the other table

    Hello

    could you help me with the following question?

    I have the following tables

    CREATE TABLE table1)

    ID varchar (12),

    col2 varchar (10),

    COL3 varchar (10),

    level varchar (10))

    CREATE TABLE table2)

    Id2 varchar (12)

    A varchar (10),

    B number (1)

    CONSTRAINT PRIMARY KEY PK (ID2, is));

    INSERT INTO table2 (ID2, A, B) SELECT ID, col2

    MAX (CASE WHEN level = "level 1" then 1

    level = 'level 2' then 2

    Level = 3 then 'niveau3') as colIN3)

    FROM table1 GROUP BY ID2, a.;

    the first table have duplicates as follows:

    Id2 COL2 COL3 level

    A1 pepe football level1

    A1 pepe football level2

    A1 pepe football level1

    A1 pepe basket level2

    A1 pepe pingpong level3

    the output should be selected with unique key (ID2, col3) lines and the level must be the greatest.

    Id2 COL2 COL3 level

    A1 pepe football level2

    A1 pepe basket level2

    A1 pepe pingpong level3

    The output of the script tells me the following messages:

    -lack of right parenthesis referring to the max function.

    Thanks adavance.

    Kind regards

    Hello

    Remember the ABC's of the GROUP BY:

    When you use a GROUP BY clause or in an aggregate function, then all in the SELECT clause must be:

    (A) a ggregate function,

    (B) one of the expressions "group By."

    (C) adding to C, or

    (D) something that Depends on the foregoing.  (For example, if you "GROUP BY TRUNC (dt)", you can SELECT "TO_CHAR (TRUNC (dt), 'Mon - DD')").

    To ask him, there are 5 columns in the SELECT clause.  The last one is a function MAX (...); It is an aggregate, is not serious.

    The first 2 columns are also named in the GROUP BY clause, so that they are well.

    The other 2 columns, country and internal_Id do not match any of the above categories.  These 2 columns cause the error.

    There are many ways to avoid this error, each producing different results.  You could

    • remove these 2 columns in the SELECT clause
    • Add these 2 columns in the GROUP BY clause
    • use the aggregation such as MIN, 2-column functions
    • remove the country from the SELECT clause and add internal_id to the GROUP BY clause
    • remove the internal_id from the SELECT clause, and add countries to the GROUP BY clause
    • ...

    What are the results you want?

    Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas.  Also post the results you want from this data, as well as an explanation of how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • How to get data in the procedure after CREATE TABLE table1 AS SELECT * from table2

    Hello

    can any body tell me how to get the data in the new table created in the procedure. because it gives following error.

    • Error (47,21): PL/SQL: ORA-00942: table or view does not exist

    tableName: = "BCKUP_" | TO_CHAR (sysdate, 'ddmmrrrr');

    tableDDL: = 'CREATE TABLE' | tableName. "AS SELECT * FROM Table1 where to_char(MSG_IN_TIME,''dd-mon-rrrr'') < sysdate - ' | daysNumber;

    EXECUTE IMMEDIATE backUpDDL;

    COMMIT;

    DELETE FROM Table1;

    How to select the data in the newly created table. as...

    Select * from ". tableName;

    Do not choose anything to get the number...

    Just after backupDDL EXECUTE IMMEDIATE, simply refers to SQL % ROWCOUNT - who will be the number of lines.

    Oh and DDL engages automatically, your commitment is redundant.

  • get information from inside a trigger of the other tables in the schema even

    Addendum:

    ... Sorry I forgot: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64 bit

    *******************

    Hello

    I'm trying for a few hours to get information from inside a trigger to another table in the same pattern.

    My trigger is PSE_BKB. NUM_PHANTOM_BP

    I first tried a simple solution...


    CREATE OR REPLACE TRIGGER PSE_BKB. NUM_TR_PHANTOM_BP
    BEFORE DELETING, INSERTION OR UPDATE
    ON PSE_BKB. NUM_PHANTOM_BP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    DECLARE

    v_recht NUMBER (1): = 0;
    v_recht2 NUMBER (1): = 0;
    v_change_mitarbeiter NUMBER (1): = 0;
    v_recht_mitarbeiter NUMBER (1): = 0;
    v_typ varchar2 (20);
    v_obj_key varchar2 (11): = "gugus";
    v_ph_key varchar2 (11);
    -ph_key varchar2 (11);
    v_obj_keys varchar2 (4000): = ', ';

    anz_num NUMBER: = 0;
    anz_num_tmp NUMBER: = 0;
    anz_st_si NUMBER: = 0;


    BEGIN

    ...
    Select count (*)
    in anz_num
    of pse_bkb.num_objekt o
    where o.obj_key in
    (select distinct (ov.obj_key)
    of pse_bkb.num_objekt_verb ov
    where ov.phantom_key =: old.phantom_key
    )
    and o.typ = "NUM";

    ...

    Explanation: my trigger table is PSE_BKB. NUM_PHANTOM_BP.

    On the pse_bkb.num_objekt_verb of the table, I have a relationship 1: n to one or several object-key (field named obj_key!) on my referenced key: old.phantom_key. With this obj_key, I want to watch the weather, I have one or more lines in the table type num_objekt "NUM". So the internal selection gives me all the num_objekt_verb obj_key with my: old.phantom_key and with whom I count the number of lines I have on num_objekt with type "NUM".

    The problem is that the trigger does not see the table.

    I tried many variations.

    The latest version I tried was with a cursor inside the trigger definition as in the block of code below.

    For debugging purposes, I inserted a RAISE_APPLICATION_ERROR in the inner loop - see below. The v_obj_key variable is never defined, as in all the other variations, I tried-, I still see the predefined "gugus" in the declare section.

    It seems that oracle can not read other tables at this point. La: old.phantom_key is defined (in this simple example there would come a return obj_key).

    Thanks in advance for your help - and excuse my English.

    Trigger code:

    CREATE OR REPLACE TRIGGER PSE_BKB. NUM_TR_PHANTOM_BP
    BEFORE DELETING, INSERTION OR UPDATE
    ON PSE_BKB. NUM_PHANTOM_BP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    DECLARE

    v_recht NUMBER (1): = 0;
    v_recht2 NUMBER (1): = 0;
    v_change_mitarbeiter NUMBER (1): = 0;
    v_recht_mitarbeiter NUMBER (1): = 0;
    v_typ varchar2 (20);
    v_obj_key varchar2 (11): = "gugus";
    v_ph_key varchar2 (11);
    -ph_key varchar2 (11);
    v_obj_keys varchar2 (4000): = ', ';

    anz_num NUMBER: = 0;
    anz_num_tmp NUMBER: = 0;
    anz_st_si NUMBER: = 0;


    BEGIN


    Start
    declare

    cursor nums is

    Select obj_key
    of PSE_BKB.num_objekt_verb
    where phantom_key =: old.phantom_key;

    Start

    for the RC looping nums
    v_obj_key: = cr.obj_key;

    RAISE_APPLICATION_ERROR (-20099,' AGAIN 9 v_obj_key: ' | v_obj_key |) ': old.phantom_key ' | (: old.phantom_key);

    When the exit nums % NOTFOUND;

    Select count (*) in the pse_bkb.num_objekt anz_num_tmp where obj_key = v_obj_key and type = "NUM";
    anz_num: = anz_num + anz_num_tmp;
    end loop;

    end;
    end;

    Published by: user832075 on 14.01.2013 06:18

    The reason why you get count_n = 0 in tr_c is that there is no line in B with key_c = 17, to the moment you arrive at tr_c. The removal of B has already occurred, and since you're in a single transaction, the application for tr_c:

    select count(*)
      into   counter_n
      from   a aa
      where  aa.key_a in (select distinct(bb.key_a)
                          from   b bb
                          where  bb.key_c = v_ph_key
                         )
      and    aa.typ = 'n';
    

    'knows' that the row has been deleted then gets a number of 0.

    I added a set of instructions dbms_output to show the order in which triggers run, and that's what I get:

    SQL> delete from b_vw where key_a = 1 and key_c = 17 ;
    in trigger b_tr_vw
    In tr_b
    in tr_c
    delete from b_vw where key_a = 1 and key_c = 17
                *
    ERROR at line 1:
    ORA-20077: Remark: counter_n: 0 counter_s: 0 v_ph_key: 17 old.key_c: 17
    new.key_c:
    ORA-06512: at "OPS$ORACLE.TR_C", line 38
    ORA-04088: error during execution of trigger 'OPS$ORACLE.TR_C'
    ORA-06512: at "OPS$ORACLE.B_TR_VW", line 17
    ORA-04088: error during execution of trigger 'OPS$ORACLE.B_TR_VW'
    

    Thus b_tr_vw trigger is triggered first and deletes a B. trigger fires tr_b as part of this statement to remove and check against A, happening apparently so no error is triggered and succeeds the removal of B. Now tr_b_vw takes back control and deletes C. Since the B line which has key_c = 17 already deleted a control for counter_n > 0 and counter_s = 0 fails and raise you the-20002 error. Note that I'm assuming that the error of-20077 you lift is just to see the values and is not intended to be part of your actual code.

    Because I have really no idea what you're trying to accomplish here I can't offer a lot of advice that you might want to try entering two tr_c of the tr_b_vw trigger validation queries before deliver you the removal of b and put the counter_n > 0 and counter_s = 0 control under tr_b_vw to decide whether or not you want to remove.

    John

  • need a script to create multiple tables as the other columns in tables

    I need script to create multiple tables as the other columns of tables respectively.

    lets consider I want to create tables from table1... table99 like tablex1... .tablex99 columns (without data) respectively (i.e table1 as tablex1, table99 as tablex99).
    declare
    
    cursor c is select object_name from all_objects where object_type='TABLE';
    
    begin
    
    for i in c loop
    
    execute immediate 'create table '||i.object_name||'_x as select * from '||i.object_name||' where 1=2';
    
    end loop;
    
    end;
    
    use can use this and put your user names accordingly.
    If you get any error please post the error.
    
  • create the table in SELECT (question)

    Hello

    In regards to create the table as subquery, I read that:

    The data type of column definitions and the NOT NULL constraint are passed to the new table. Note that only the explicit NOT NULL constraint is inherited. The PRIMARY KEY column will not function NOT NULL column null. Any other rule of constraint is not passed to the new table. However, you can add constraints in the column definition.

    Can someone explain to me how to do this? Or, how we need to specify the constraints (and also the default values for columns, because it is possible) for the columns in the column definition?

    In addition, I do not understand this: the PRIMARY KEY column will not function NOT NULL column zero.
    Can someone give me some small examples regarding these?
    For example, it generates an error:
    create table test1 (a, b, c default sysdate) 
    as 
    select 1, 'b' from dual
    Thank you!

    Edited by: Roger22 the 01.09.2011 11:37

    Hello

    When you set a primary key consists of a unique constraint and a constraint not null, but they are both implicit with the primary key. When you create the table because it will copy only the explicitly declared NOT NULL constraints so it isn't look upward than the implicit NOT NULL primary key.

    SQL> create table dt_pk
      2  (   id      number primary key,
      3      col1    number not null,
      4      col2    number
      5  )
      6  /
    
    Table created.
    
    SQL> desc dt_pk
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> create table dt_pk2 as select * from dt_pk;
    
    Table created.
    
    SQL> desc dt_pk2;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                                 NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> select constraint_name,constraint_type from user_constraints where table_name='DT_PK'
      2  /
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C006935772                 C
    SYS_C006935773                 P
    
    SQL> select constraint_name,constraint_type from user_constraints where table_name='DT_PK2'
      2  /
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C006935774                 C
    

    However, a primary key can reuse existing constraints and indexes instead of declaring new. For example, we can explicitly declare a constraint not null on the column id and then create a primary key. This means that we will now inherit the constraint not null in the ETG, as it has been explicitly declared and is a constraint separate in there own right that has been 'borrowed' by the pk constraint.

    SQL> create table dt_pk3 (id number not null, col1 number not null, col2 number);
    
    Table created.
    
    SQL> alter table dt_pk3 add constraint dt_pk3_pk primary key (id);
    
    Table altered.
    
    SQL> select constraint_name,constraint_type from user_constraints where table_name='DT_PK3'
      2  /
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C006935775                 C
    SYS_C006935776                 C
    DT_PK3_PK                      P
    
    SQL> create table dt_pk4 as select * from dt_pk3;
    
    Table created.
    
    SQL> desc dt_pk3;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> desc dt_pk4;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER 
    

    Regarding the definition of the default values, you must always specify the column in the select, but doing so means follow you the semantics of a default in a standard INSERT statement, i.e. you specified the column, you must provide a value, in which case even if the value is null, the default value will not be used. However, the new inserted rows where the column with the default value is not specified will revert to the default.

    SQL> create table test1 (a, b, c default sysdate)
      2  as
      3  select 1, 'b' from dual
      4  /
    create table test1 (a, b, c default sysdate)
                        *
    ERROR at line 1:
    ORA-01730: invalid number of column names specified
    
    SQL> create table test1 (a, b, c default sysdate)
      2  as
      3  select 1, 'b', null c from dual
      4  /
    select 1, 'b', null c from dual
                   *
    ERROR at line 3:
    ORA-01723: zero-length columns are not allowed
    
    SQL> create table test1 (a, b, c default sysdate)
      2  as
      3  select 1, 'b', cast(null as date) c from dual
      4  /
    
    Table created.
    
    SQL> select * from test1;
    
             A B C
    ---------- - ---------
             1 b
    
    SQL> insert into test1(a,b) values(2,'b');
    
    1 row created.
    
    SQL> select * from test1;
    
             A B C
    ---------- - ---------
             1 b
             2 b 01-SEP-11
    

    To create a constraint, you must list all columns without the data types and constraints list online.

    SQL> create table dt_cons (id number, col1 number, col2 number, constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    create table dt_cons (id number, col1 number, col2 number, constraint chk2 check(col2 IS NULL or col2>10))
                          *
    ERROR at line 1:
    ORA-01773: may not specify column datatypes in this CREATE TABLE
    
    SQL> create table dt_cons (constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    create table dt_cons (constraint chk2 check(col2 IS NULL or col2>10))
                         *
    ERROR at line 1:
    ORA-00904: : invalid identifier
    
    SQL> create table dt_cons (col2 constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    create table dt_cons (col2 constraint chk2 check(col2 IS NULL or col2>10))
                          *
    ERROR at line 1:
    ORA-01730: invalid number of column names specified
    
    SQL> create table dt_cons (id,col1,col2 constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    
    Table created.
    
    SQL> desc dt_cons
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> insert into dt_cons values(2,2,2);
    insert into dt_cons values(2,2,2)
    *
    ERROR at line 1:
    ORA-02290: check constraint (JJACOB_APP.CHK2) violated
    
    SQL> insert into dt_cons values(2,2,10);
    insert into dt_cons values(2,2,10)
    *
    ERROR at line 1:
    ORA-02290: check constraint (JJACOB_APP.CHK2) violated
    
    SQL> insert into dt_cons values(2,2,11);
    
    1 row created.
    
    SQL> insert into dt_cons values(2,2,null);
    
    1 row created.
    
    SQL>
    

    HTH

    David

  • Trying to create the table using Clause any Union with Select multiple stmts

    The motion seeks to get the substring of the value to for example.
    If the value is * ASA 2 * then so do ASA
    where as if the value is * 1.5 TST * it sholud come as TST as wise for others too.
    I am trying to execute stmt SQL written but in error as below:

    * ' ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias. "

    CREATE TABLE TEST_CARE AS
    (
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 5
    UNION ALL
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 7
    UNION ALL
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 14
    UNION ALL
    Row_id SELECT, old_care_lvl, SUBSTR (old_care_lvl, 3), LEN test_care_lvl
    WHERE LENGTH = 7 AND old_care_lvl (old_care_lvl) = "Regular."
    );

    I want to create the table using the above given the multiple selection by using the Union ALL clause, but trying to create run query error like "ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias.

    Please guide me how to approach to solve this problem.
    Thanks in advance.

    Try this->

    CREATE TABLE TEST_CARE
    AS
      select *
      from (
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =5
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =7
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =14
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
          );
    

    N.B.: Not tested...

    Kind regards.

    LOULOU.

  • Procedure with the DML statements that insert values from 1 to 100 in only one table and it is matching word equivalent in the other

    Can someone help me create a procedure with the DML statements that insert values from 1 to 100 in a table "abc" and the procedure must connect the numbers into words in another table "xyz" without doing a commit explicitly. "."

    Currently on trial...

    SQL > create table abc (num number);

    Table created.

    SQL > create table xyz (num varchar2 (100));

    Table created.

    SQL > ed
    A written file afiedt.buf

    1. insert all
    2 values of 1 = 1 then in abc (num) (l)
    3 when the values of 1 = 1 then in xyz (num) (to_char (to_date(l,'j'), 'jsp'))
    4 * Select the level from dual connect by level<=>
    SQL > /.

    200 rows created.

    And the result...

    SQL > select * from abc;

    NUM
    ----------
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ..
    ..
    ..
    98
    99
    100

    100 selected lines.

    SQL > select * from xyz;

    NUM
    ----------------------------------------------------------------------------------------------------
    one
    two
    three
    four
    five
    six
    seven
    eight
    nine
    ten
    Eleven
    twelve
    ..
    ..
    ..
    98
    Nineteen eighty
    Cent

    100 selected lines.

  • fill a field from the sum and the other two table group

    I have a table named dgpercentagedatachart that has a field
    called totalcecrating which must be completed

    dgpercentagedatachart is my target table

    To fill in this field, I will use two existing tables

    Table 1 = rental service

    Table 2 = meter

    I need the SUM of the KW of field in table 2 GROUPBY feederid in table 1

    Table 1 and table 2 common field is the objectid tbl1 and servicelocationid
    for tbl 2, so this is will be the join I will use

    It of what I have so far in my query, but are unable to complete
    correctly. I need help!

    Insert into dgpercentagedatachart (totalcecrating)

    using servicelocation (objectid)

    Sum (kW)

    innerjoin servicelocation meter

    on meter.servicelocationid = servicelocaid.objectid

    GROUP BY servicelocation.feederid;

    Here is my table DG % (target)

    name of the field type Nullable

    TOTALCECRATING NUMBER (38.0) Yes

    FEEDERID NVARCHAR2 (255 CHAR) Yes

    NUMBER (38.8) PERCENTAGE Yes

    LOWESTFEEDERRATING NUMBER (38.0) Yes

    OBJECTID NUMBER (38.0) No.

    DG % DATACHART

    DATA

    FEEDERID TOTALCECRATING

    X 33

    X 33

    X 121

    X 122

    ServiceLocation table (table 1)

    fieldName nullable datatype

    OBJECTID NUMBER (38.0) No.

    Yes FEEDERID VARCHAR2 (20 BYTES)

    Data

    OBJECTID FEEDERID

    61897 X 33

    61898 X 33

    61899 X 33

    61900 X 33

    B521 141287

    Counter table (table2)

    fieldName Nullable Datatype

    Yes NUMBER (38.8) KW

    OBJECTID NUMBER (38.0) No.

    ID ServiceLocation source KW

    PV 0 162756

    194720 PV 1.01

    106697 PV 1.2

    195975 PV 1.2

    133967 PV 1.5

    105461 PV 1.6

    365278 PV 1.62

    Hello

    2685870 wrote:

    That's what I received your reply:

    Select sum (m.kw), servicelocation.feederid

    of servicelocation sl, meter m

    where to meter servicelocation inner join

    on meter.servicelocationid = servicelocation.objectid

    Servicelocation.feederid group;

    ...

    You are mixing up in two different ways to do joins.

    ANSI join syntax uses the keyword JOIN between table names and the join conditions, after the keyword, all in the FROM clause, like this:

    OF sevicelocation sl

    JOIN meter m ON m.servicelocattionid = sl.objectid

    The old Oracle syntax has commas between the names of tables in the FROM clause and the join conditions go in a WHERE clause.  JOIN keywords and THEY are not used.  For example:

    OF serviceloation sl

    meter m

    WHERE m.servicelocattionid = sl.objectid

    Do not use both in the same query.  Use one or the other consistently.  (I recommend the ANSI rating.)

  • Problem when selecting a table after you have created the dblink

    Hello

    We have created the dblink for oracle to sql server and created successfully,

    But while selecting the oracle table, we receive the question below,

    Select * from 'sysdiagrams"@omniyat;

    ERROR on line 1:

    ORA-00942: table or view does not exist

    [Microsoft] [ODBC SQL Server driver] [SQL Server] Incorrect object name

    'sysdiagrams '. {42S 02, NativeErr = 208} [Microsoft] [ODBC SQL Server driver] [SQL

    Server] instructions could not be prepared. {NativeErr 42000, 8180 =}

    ORA-02063: preceding 2 lines of DAMAC

    Please provide us with the solution for this problem.

    Concerning

    Sham

    Hi S27.

    We had the similar problem, and I guess you went to the database MSSQL and verified that the table exists in fact.

    The problem we encountered was that we were in the wrong database on the instance of MSSQL.  I am unsure of your Setup, but if this is your case, you can try either by setting the database default to the ODBC connection to the correct on the instance MSSQL database (can be done on Windows, I'm not sure about Linux), or you can USE the command through the :

    SELECT
         DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@<> ('USE <>')
    FROM DUAL;
    

    You try your select statement from the DB link.

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

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

    WELCOME

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

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

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

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

    Is the same for the box:

    echo '';
    

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

  • How to create a report based on the item selected from the list of selection?

    Hello

    I created a tables_LOV based on:

    Select table_name table_name user_tab_cols r, d

    where column_name like '% _type % '.

    Then I created a ListOfTables page element, display in a selection list and pointing to tables_LOV.

    I run the page, and I can choose the table I want in the drop-down list.

    How to create a report based on the selected element? (ex: select * from selected_table)

    Thanks in advance

    Salah

    Hi Salah,

    Allright, take a look at this page: http://apex.oracle.com/pls/apex/f?p=vincentdeelen:collection_report

    I think that simulates what you are trying to accomplish. I've implemented the simplest method I could think of.

    The report is based on a collection of apex. If you are not familiar with this, you should study the documentation: APEX_COLLECTION

    To recreate my example, you should:

    (1) create a report (interactive) on your collection

    SELECT *
       FROM APEX_collections
     WHERE collection_name = 'MY_COLLECTION'
    

    (2) create a selection list page_item for the tables that you want to display (in my case, this is called "P38_TABLES")

    (3) create a dynamic action that triggers on the evolution of your selection list page_item. Dynamic action must be a parade of PL/SQL procedure the following code:

    declare
      l_query varchar2(4000);
    begin
      l_query := 'select * from '||:P38_TABLES;
      if apex_collection.collection_exists
            ( p_collection_name => 'MY_COLLECTION' )
      then
        apex_collection.delete_collection
          ( p_collection_name => 'MY_COLLECTION' );
      end if;
    
      apex_collection.create_collection_from_query
        ( p_collection_name => 'MY_COLLECTION'
        , p_query           => l_query
        );
    end;
    

    Make sure that you add your page_item 'Page to send items' section.

    (4) add a real extra action that makes an update of the report area.

    Here are two photos describing the da:

    http://www.vincentdeelen.com/images/OTN/OTN_COLLECTION_REPORT_DA1.PNG

    http://www.vincentdeelen.com/images/OTN/OTN_COLLECTION_REPORT_DA2.PNG

    Good luck and greetings,

    Vincent

    http://vincentdeelen.blogspot.com

Maybe you are looking for

  • Distance between 2 points in geo coordinates

    Everyone knows hot to calculate the distance between 2 points on the surface of the Earth, given their contact details? (for example: 1=30.45N/43.23E and 2=35.11N/19.05W) A program for HP50G or 42, or 41 c would be fine, a formula or algorithm as wel

  • Compensation of temperature for the strain gauges

    I'm trying to compensate for the effects of temperature on an extensometer placed on a sample of carbon fiber.  The sample will be only responsible uniaxialement.  The temperature is a major concern here, for an electrical current will be executed by

  • Windows update/microsoft downloads impossible!

    I tried now to the pointwhere I give up! try to update windows home premium, and also when I try microsoft downloads, it will not work indicating the link always seems to be broken - he also said connection problem-i run my internet through a router

  • System does not boot: failure of the video card or viruses? I do not know...

    Here's the deal: on a computer running Windows XP Pro SP3. Athlon, dual-core processor (2.4 gHz); 4 GB of memory; NVidia GeForce 7300 video card; and a Western Digital SATA, I met a failure while watching a DVD (using Media Player 11) and now I can't

  • by mistake I delete mi ricyclebeen wht to do

    I delete my ricyclebeen newspaper office what to do to get it back