Using package types within create table?

Hallo,
can I use types, declared in a package, within a create table statement?
Example:
craete table MyTable (
MyTableID MYTYPES.TID not null,
and so on...
The package is MYTYPES and I have defined a subtype TID.
Running this part of a script, I get the error ORA-00902: invalid datatype
Using such types in a stored procedure is working fine.
Best regards
Stephan Schneider

No. Stuff inside PL/SQL packages can only be used by other PL/SQL programs.
You can use objects (aka User Defined Datatypes) as table columns if you can be bothered to.
Cheers, APC

Similar Messages

  • %TYPE in create table

    Is it possible to use %TYPE while defining table column datatype? Does Oracle support userdefined datatypes which can be used in Table-Column definition as well as stored procedure variables?

    I don't know if it helps, but this is something from the Oracle documentation:
    ==================================================================================================
    Restrictions:
    You cannot specify attributes of type ROWID, LONG, or LONG ROW.
    You cannot create an object with NCLOB, NCHAR, or NVARCHAR2 attributes, but you can specify parameters of these datatypes in
    methods.
    You cannot specify a datatype of UROWID for a user-defined object type.
    If you specify an object of type REF, the target object must have an object identifier.
    ==================================================================================================
    I am still not able to make it work with nvarchar2 data type. It is working for varchar2 datatype.
    Thanks
    Sheeba

  • Using EXECUTE IMMEDIATE with Create Table SQL Statement not working

    Hi ,
    I am all the privileges given from the SYSTEM user , but still i am not able to create a table under procedure . Please see these and advice.
    create or replace procedure sp_dummy as
    begin
    Execute Immediate 'Create table Dummy99_99 (Dummy_Field number)';
    end;
    even i tried this way also
    create or replace PROCEDURE clearing_Practise(p_file_id in varchar2, p_country in VARCHAR2,p_mapId in VARCHAR2)
    AUTHID CURRENT_USER AS
    strStatusCode VARCHAR2(6);
    BEGIN
    EXECUTE IMMEDIATE 'create table bonus(name varchar2(50))';
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('ERROR Creating Table');
    END ;

    William Robertson wrote:
    Since the syntax is correct, my guess is you do not have CREATE TABLE system privilege granted directly to your account. A common scenario is that you have this privilege granted indirectly via a role, allowing you to create tables on the command line, but stored PL/SQL is stricter and requires a direct grant and therefore the procedure fails with 'insufficient privileges'.A bit like he's already been told on his first thread...
    Using of Execute Immediate in Oracle PLSQL
    Generally you would not create tables from stored PL/SQL. Also as you have found out, it's best not to hide exceptions with 'WHEN OTHERS THEN [some message which gives less detail than the one generated by Oracle]'.Again like he was told on the other thread.
    There's just no telling some people eh! :)

  • NESTED Tables for Sub-types when creating table for Super-type

    If I create the following types, as an example:
    Person with subtypes: Employee and Customer
    Appointment
    CREATE OR REPLACE TYPE Person_OT AS OBJECT (
    person#                         NUMBER,
    personSurname                    VARCHAR2(50),
    personForenames               VARCHAR2(50),
    personDateOfBirth               DATE,
    personAddress                    Address_OT,
    ) NOT FINAL ;
    CREATE OR REPLACE TYPE Employee UNDER Person_OT (
    empSalary               NUMBER,
    empNoSales          NUMBER,
    makes               Appointment_List_OT
    ) FINAL ;
    CREATE OR REPLACE TYPE Appointment_OT AS OBJECT (
    some attributes
    CREATE OR REPLACE TYPE Appointment_List_OT AS TABLE OF REF Appointment_OT ;
    When creating the table to hold objects of Person type, how can the requisite nested table for representing 'makes' be declared? The below approach is not correct, however the table will not compile without naming the nested tables.
    CREATE TABLE Person_TBL OF Person_OT (
    Person#     PRIMARY KEY)
    NESTED TABLE makes STORE AS Appointment_List_NTBL;
    Advice very much appreciated!

    CREATE TABLE Person_TBL OF Person_OT(
    Person# PRIMARY KEY)
    NESTED TABLE TREAT(SYS_NC_ROWINFO$ AS EMPLOYEE).MAKES STORE AS Appointment_List_NTBL
    Table created.
    SQL> select * from user_nested_tables
      2  /
    TABLE_NAME                     TABLE_TYPE_OWNER
    TABLE_TYPE_NAME                PARENT_TABLE_NAME
    PARENT_TABLE_COLUMN
    STORAGE_SPEC                   RETURN_TYPE          ELEMENT_SUBSTITUTABLE
    APPOINTMENT_LIST_NTBL          SCOTT
    APPOINTMENT_LIST_OT            PERSON_TBL
    TREAT(SYS_NC_ROWINFO$ AS "SCOTT"."EMPLOYEE")."MAKES"
                           DEFAULT                VALUE                         N
    SQL>  SY.

  • How to use database link to create table in other database?

    e.g., java jdbc is connected to the database A.
    i want to create one table (Table1)in database B, and then insert data into Table1 select ....from Table2 which is in database A.
    i used the create database link (database name) connect to (database) indentified by .....
    but ...i got the sqlException as i wrote before.
    Thanks again.

    http://forum.java.sun.com/thread.jspa?threadID=656868&messageID=3860293#3860293

  • Problem with External Table using ORACLE_INTERNAL TYPE in 9i release 2

    Hi,
    I have tried to create an external table in oracle 9i release 2 using the following qurey:
    CREATE TABLE emp_ext
    ORGANIZATION EXTERNAL
    ( TYPE ORACLE_INTERNAL
    DEFAULT DIRECTORY admin_dat_dir
    LOCATION(admin_dat_dir:'emp1.dmp')
    PARALLEL
    AS
    SELECT * from employees;
    and getting the following error message
    ORA-30657: operation not supported on external organized table
    Please help me.
    Thanks in Advance

    As a matter of fact oracle 9i has two types of api for external tables one is oracle_loader and the other is oracle_internal which in 10g become oracle_datapump.
    What my question is how can I use the other type in case of external table as we are doing in 10g? Do I need to run any script to enable this feature or is there any privillege issue?
    I've given the read, write privillege to the user and the oracle user has read/write permission in os level on the location of the directory.

  • Can use JDBC to create table in the database?

    other than select, insert, update, delete the record set
    I want to know can I use the JDBE to create table.

    As far as i know you can use 'CREATE TABLE' to create tables.
    Use it in an cn.execute() or cn.executeUpdate().
    I'm not sure about the complete syntax for CREATE TABLE, since you also need to define you fields etc. Try looking on the net for an SQL manual.
    Greetz..

  • "invalid name pattern"  when trying to user packaged TYPE

    Hi,
    I have problem with creating ArrayDescriptor instance of packaged DB TYPE.
    There is declared TYPE
       type OBJ_ARRAY_TYPE is table of number(30)
    in a DB package specification,
    when i try to create description through jdbc, it fails on "java.sql.SQLException: invalid name pattern: PKG_NAME.OBJ_ARRAY_TYPE":
       desc = ArrayDescriptor.createDescriptor ("PKG_NAME.OBJ_ARRAY_TYPE", conn);
    When OBJ_ARRAY_TYPE defined globally, outside the package, everything works fine. Is it limitation of JDBC(classes12.jar)/OracleDB9i not to allow using packaged types?
    Thx for any suggestion.

    I have same hiccup with 10g JDBC Driver (ojdbc14.jar) and 9i Database.
    Test Case: Create the package with the type and a procedure that use this type as OUT parameter. Create a java application to invoke this procedure and consume the type.
    Steps:
    Create following package.
    CREATE OR REPLACE PACKAGE test_type AS
      type avarchartabletype IS TABLE OF VARCHAR2(256) INDEX BY binary_integer;
      PROCEDURE getvcttdata(avcttdata OUT avarchartabletype,   irows IN OUT INTEGER);
    END test_type;
    CREATE OR REPLACE PACKAGE BODY test_type AS
      PROCEDURE getvcttdata(avcttdata OUT avarchartabletype,   irows IN OUT INTEGER) AS
      BEGIN
        FOR i IN 1 .. irows
        LOOP
          avcttdata(i) := 'Yo ' || i;
        END LOOP;
      END getvcttdata;
    END test_type;2. Try to execute the above procedure using following Java code:-
    public class TestType {
         public static void main(String[] args) throws Exception {
              java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
              java.sql.Connection con = java.sql.DriverManager.getConnection(args[0],
                        args[1], args[2]);
              oracle.jdbc.driver.OracleCallableStatement stmt = (oracle.jdbc.driver.OracleCallableStatement) con
                        .prepareCall("call Test_Type.getVCTTData(?,?)");
               stmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.ARRAY,
                        "test_type.avarchartabletype");
              stmt.registerOutParameter(2, oracle.jdbc.driver.OracleTypes.INTEGER);
              stmt.executeUpdate();
              // Get the ARRAY object and print the meta data assosiated with it
              oracle.sql.ARRAY simpleArray = stmt.getARRAY(1);
              System.out.println("SQLTypeName=" + simpleArray.getSQLTypeName());
              System.out.println("BaseType=" + simpleArray.getBaseType());
              System.out.println("length=" + simpleArray.length());
              String[] values = (String[]) simpleArray.getArray();
              for (int i = 0; i < values.length; i++) {
                   System.out.println("row[" + i + "]=" + values[i] + "<BR>");
              stmt.close();
              con.close();
    Result:
    Exception in thread "main" java.sql.SQLException: invalid name pattern: test_type.avarchartabletype
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
         at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java:463)
         at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java:362)
         at oracle.sql.ArrayDescriptor.initPickler(ArrayDescriptor.java:1756)
         at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:272)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:196)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:165)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:150)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:115)
         at oracle.jdbc.driver.NamedTypeAccessor.otypeFromName(NamedTypeAccessor.java:71)
         at oracle.jdbc.driver.TypeAccessor.initMetadata(TypeAccessor.java:79)
         at oracle.jdbc.driver.T4CCallableStatement.allocateAccessor(T4CCallableStatement.java:630)
         at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:133)
         at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:179)
         at TestType.main(TestType.java:32)
    This works fine when execute as PL/SQL using following snippet.
    declare
      thepage   Test_Type.aVarCharTableType;
      irows     integer       := 10;
      cl        clob;
      begin
      Test_Type.getVCTTData(thepage, irows);
       for i in 1 .. irows
       loop
         cl := thepage (i);
         dbms_output.PUT_LINE(cl);
       end loop;
    end;Message was edited by:
    bonjonbovi

  • J2ee tutorial. "ant create-tables" problem

    I am following Java ee 5 tutorial. In one of its sections it asks me to populate the db by following the below instructions:
    1. In a terminal window, go to the books directory or any one of the bookstore1 through
    bookstore6 example directories.
    2. Start the JavaDB database server. For instructions, see ?Starting and Stopping the JavaDB
    Database Server? on page 69. You don?t have to do this if you are usingNetBeans IDE. It
    starts the database server automatically.
    3. Type ant create-tables. This task runs a command to read the file tutorial.sql and
    execute the SQL commands contained in the file.
    4. At the end of the processing, you should see the following output:
    [sql] 181 of 181 SQL statements executed successfully
    when i reach step 3 and type ant create-tables, i get the following error:
    C:\netbeans-javatutorials\JavaEE5Tutorial\J2EEe-tutorial_5\examples\web\books>ant create-tables
    Buildfile:build.xml
    -pre-init:
    check:
    BUILD FAILED
    C:\netbeans-javatutorials\JavaEE5Tutorial\J2EEe-tutorial_5\examples\bp-project\app-server-ant.xml:419: Property javaee.server.passwordfile not specified. Please specify the javaee.server.passwordfile property in 'bp-project/build.properties'. You will also need to ensure that the passwordfile is present and contains AS_ADMIN_PASSWORD.
    Total time :0 seconds
    I have configure the build.properties file as follows:
    # Set the property javaee.home, using the path to your
    # GlassFish installation.
    # C:/Program Files/glassfish-v3 is the GlassFish v3 default installation
    # path on Windows.
    javaee.home=C:/Sun/AppServer
    # Set the property javaee.tutorial.home to the location where you
    # installed the Java EE Tutorial bundle.
    javaee.tutorial.home=C:/netbeans-javatutorials/JavaEE5Tutorial/J2EEe-tutorial_5
    # machine name (or the IP address) where the applications will be deployed.
    javaee.server.name=localhost
    # port number where GlassFish applications are accessed by users
    javaee.server.port=8080
    # port number where the Admin Console of GlassFish is available
    javaee.adminserver.port=4848
    # Uncomment the property javaee.server.username,
    # and replace the administrator username of the app-server
    javaee.server.username=admin
    # Uncomment the property javaee.server.passwordfile,
    # and replace the following line to point to a file that
    # contains the admin password for your app-server.
    # The file should contain the password in the following line:
    # AS_ADMIN_PASSWORD=adminadmin
    # Notice that the password is adminadmin since this is
    # the default password used by GlassFish.
    javaee.server.passwordfile=C:/netbeans-javatutorials/JavaEE5Tutorial/J2EEe-tutorial_5/examples/common/admin-password.txt
    appserver.instance=server
    # Uncomment and set this property to the location of the browser you
    # choose to launch when an application is deployed.
    # On Windows and Mac OS X the OS default browser is used.
    #default.browser=/Applications/Firefox.app/Contents/MacOS/firefox-bin
    # Database vendor property for db tasks
    # JavaDB is the default database vendor. See the settings in javadb.properties
    db.vendor=javadb
    # Digital certificate properties for mutual authentication
    keystore=${javaee.tutorial.home}/examples/jaxws/simpleclient-cert/support/client_keystore.jks
    truststore=${javaee.home}/domains/domain1/config/cacerts.jks
    keystore.password=changeit
    truststore.password=changeit
    and the admin-password.txt
    AS_ADMIN_PASSWORD=adminadmin
    Any suggestions.

    I was stuck with the same problem but finally managed to get it to work.
    The only difference being, I did not change the "javaee.server.passwordfile" field. Like someone else said, I just changed the first two fields. The following are the values I set for the GlassFish 3.1 server with NetBeans 6.7.1,
    javaee.home=C:/Sun/AppServer
    javaee.tutorial.home=C:/JavaWork/javaeesuntutorial/javaeetutorial5
    Hope this helps.

  • Create table space command with no specification of data file path.

    I am using following command for creating table space in oracle 11g
    CREATE TABLESPACE testTbSpace DATAFILE 'dataFileName.dbf' SIZE 50M REUSE AUTOEXTEND ON NEXT 1M MAXSIZE 32767M NOLOGGING"
    But it is creating datafile dataFileName.dbf at disk at following path
    echo $ORACLE_HOME/dbs
    I dont want to create datafile at this path and also dont want to specify data file path in 'create table space' command.
    Is there is any parameter,which i can set and above command start to create dataFileName.dbf at that path
    Edited by: user8680179 on May 15, 2012 1:54 AM

    user8680179 wrote:
    i issued following commands from 'SYS' user;
    1. show parameter db_create_file_dest;
    NAME TYPE VALUE
    db_create_file_dest string
    2.alter system set db_create_file_dest='dataFilePath';
    System altered.
    3.show parameter db_create_file_dest;
    NAME TYPE VALUE
    db_create_file_dest string dataFilePath
    4.CREATE TABLESPACE testTbSpace2 DATAFILE 'test1.dbf' SIZE 50M REUSE AUTOEXTEND ON NEXT 1M MAXSIZE 32767M NOLOGGING;
    Tablespace created.
    But still my test1.dbf file is creating at old path($ORACLE_HOME/dbs)Is datafilepath a real location? I don't think so! Give a proper path like "d:\oracle\" and retry.
    Aman....

  • CREATE TABLE  integer  replaced by  NUMBER(38)..

    Hi,
    I am using Oracle 11.1.0.6.O. Create a table using following query.
    CREATE TABLE VENDOR_MASTER_new (
    VENDOR_ID integer,
    VENDOE_NAME VARCHAR2(50 CHAR),
    STATUS smallint DEFAULT 1
    Table Created.
    check the table structure using DESC VENDOR_MASTER_new
    It showing
    SQL> desc vendor_master_new
    Name Null? Type
    VENDOR_ID NUMBER(38)
    VENDOE_NAME VARCHAR2(50 CHAR)
    STATUS NUMBER(38)
    SQL>
    integer replaced by NUMBER(38)..
    if it is possible to make integer. help me resolve this issue.

    954124 wrote:
    Hi,
    I am using Oracle 11.1.0.6.O. Create a table using following query.
    CREATE TABLE VENDOR_MASTER_new (
    VENDOR_ID integer,
    VENDOE_NAME VARCHAR2(50 CHAR),
    STATUS smallint DEFAULT 1
    Table Created.
    check the table structure using DESC VENDOR_MASTER_new
    It showing
    SQL> desc vendor_master_new
    Name Null? Type
    VENDOR_ID NUMBER(38)
    VENDOE_NAME VARCHAR2(50 CHAR)
    STATUS NUMBER(38)
    SQL>
    integer replaced by NUMBER(38)..
    if it is possible to make integer. help me resolve this issue.
    That should be fine as number(38) is having one much bigger range than integer.

  • To make the query more efficient (create table wiht select command)

    Hi,
    I have written this query to create another table, but it takes approx two hours while both tables are indexed with 891353, 769023, i have used the following query.
    create table source1 as select a.idx, a.source from tt a where a.idx not in (select b.idx from ttt b)
    thanks

    Try this one if you're on oracle 8i or older
    create table source1 as
      select a.idx, a.source
        from tt a
       where not exists (select null from ttt b where a.idx = b.idx)

  • Create table query taking too long..

    Hello experts...
    I am taking the backup of table A which consist of 135 million records...
    for this am using below query..
    create table tableA_bkup as select * from tableA;
    it is taking more than hour..still running....
    is there any other way to query fast....
    thanks in advance....

    CTAS is one of the fastest ways to do such a thing.
    Remember you duplicate data. THis means if your table holds 50GB of data then it will have to copy those 50GB of data.
    A different way could be to use EXPDP to create a backup dump file from this table data. However I'm not sure if there is a big performance difference.
    Both versions could profit from parallel execution.

  • SQL Developer  Create Table Statement to ERD Visio Diagram

    I have the following Create table statement from SQL Developer and I am trying to generate an ERD Diagram using 2003 Visio. I was wondering what I need to do to convert the Create Table to an ERD Diagram Using Visio. Thanks
    CREATE TABLE “TT_TEAM”.”HR_REVOKED_SECURITY_ORGS”
    “ID” NUMBER NOT NULL ENABLE,
    “ACAT_CODE” VARCHAR2(6 BYTE) NOT NULL ENABLE,
    “APPR_SEQ_NO” NUMBER(3,0) NOT NULL ENABLE,
    “USER_ID” VARCHAR2(30 BYTE) NOT NULL ENABLE,
    “ACTION_IND” VARCHAR2(1 BYTE) NOT NULL ENABLE,
    “ACTIVITY_DATE” DATE NOT NULL ENABLE,
    “COAS_CODE” VARCHAR2(1 BYTE),
    “ORGN_CODE” VARCHAR2(6 BYTE),
    “POSN” VARCHAR2(6 BYTE) NOT NULL ENABLE,
    “MANDATORY_APPR_IND” VARCHAR2(1 BYTE),
    “APPR_POSN” VARCHAR2(6 BYTE),
    “ORGN_MANAGER” VARCHAR2(6 BYTE) NOT NULL ENABLE;

    I'm pretty Visio is a non-Oracle product.
    In the mean-time, you can easily import a DDL script file and create a relational model/diagram using SQL Developer. Use the Import feature and point to your CREATE TABLE script(s)

  • Create-tables problem

    hi,
    i've re-posted this into a new post.
    i'm following the java ee tutorial at sun.com and i'm having a problem with the bokstore1 example.
    i've set the password file correctly and when i go to the bookstore1 dir and type 'ant' everything seems ok.
    the problem i'm having is once i've started the server and DB server and then type ' ant create-tables' the build fails and i get this output-
    "Starting database it the background. log redirected to c:\SunAppserver\......\....\...db.log
    comand start-database failed
    delete-tables:
    BUILD FAILED
    C:\javaeetutorial5\bp-project\database-ant.xml:48: c:\sun\appserver\javadb\lib not found"
    can anyone help?
    thanks in advance
    mat

    Based on the info. provided, seems to me the value for 'javaee.home' in build.properties may not be correct. Make sure that the property javaee.home in build .properties pints to valid installtion of application server, for ex. if you do 'dir' or 'ls' you should see javadb directory at this location.
    Also check if you have a build.properties file under windows user directory (in addition to bp-project under tutorial) and if it points to a different application server installation.
    - sreeni

Maybe you are looking for