error with parameters when inserting data in oracle - vb.net

good afternoon,
I've been wanting to insert into oracle for several hours but I have a message that refers to the
parameters, I'm testing with a table with only 2 columns to test, but I can't find the problem.
Please appreciate any help.
error code: ORA-01036: INVALID NUMBER / VARIABLE
***The connection to the database is correct.
***Try the insert without the ID column, with the same result.
***visual studio 2019,framework 4.6.1
Imports System.Data
Imports System.Data.OracleClient
Imports System.Windows.Forms
Imports SpreadsheetLight
Public Class Form1
<Obsolete>
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim _connString As String = "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = MYSERVER))); User Id=uss; password=password;"
Dim sl As SLDocument = New SLDocument("C:\folder\NOMBRE.xlsx")
Dim propiedades As SLWorksheetStatistics = sl.GetWorksheetStatistics
Dim ultimafila = propiedades.EndRowIndex
Using conn As OracleConnection = New OracleConnection(_connString)
conn.Open()
Dim ot As OracleTransaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)
For i = 3 To ultimafila
Try
Using cmd As OracleCommand = New OracleCommand()
Const sql As String = "insert into TABLAPRUEBA(ID,NOMBRE) values (#ID,#NOMBRE)"
cmd.Connection = conn
cmd.Transaction = ot
cmd.Parameters.Add("#ID", "5")
cmd.Parameters.Add("#NOMBRE", Convert.ToString("test"))
cmd.CommandText = sql
cmd.ExecuteNonQuery()
End Using
ot.Commit()
i = i + 1
Catch ex As Exception
ot.Rollback()
MessageBox.Show("err" + ex.Message)
End Try
Next
End Using
End Sub
End Classenter code here
CREATE TABLE "myesquema"."TABLAPRUEBA"
( "NOMBRE" VARCHAR2(20 BYTE),
"ID" VARCHAR2(20 BYTE)
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
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 "myesquemaDB" ;
--------------------------------------------------------
-- DDL for Index TABLAPRUEBA_PK
--------------------------------------------------------
CREATE UNIQUE INDEX "myesquema"."TABLAPRUEBA_PK" ON "myesquema"."TABLAPRUEBA" ("ID")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "myesquemaDB" ;
--------------------------------------------------------
-- DDL for Trigger TABLAPRUEBA_TRG
--------------------------------------------------------
CREATE OR REPLACE TRIGGER "myesquema"."TABLAPRUEBA_TRG"
BEFORE INSERT ON TABLAPRUEBA
FOR EACH ROW
BEGIN
<<COLUMN_SEQUENCES>>
BEGIN
IF INSERTING AND :NEW.ID IS NULL THEN
SELECT TABLAPRUEBA_SEQ.NEXTVAL INTO :NEW.ID FROM SYS.DUAL;
END IF;
END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "myesquema"."TABLAPRUEBA_TRG" ENABLE;
--------------------------------------------------------
-- Constraints for Table TABLAPRUEBA
--------------------------------------------------------
ALTER TABLE "myesquema"."TABLAPRUEBA" MODIFY ("ID" NOT NULL ENABLE);
ALTER TABLE "myesquema"."TABLAPRUEBA" ADD CONSTRAINT "TABLAPRUEBA_PK" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "myesquemaDB" ENABLE;

You are using SQLSERVER syntax for parameters "#" but in Oracle it's different, you have to use ":"

Related

Tables are not displayed

I worked with database tables... Paradoxically, I clicked somewhere else and now there are no these tables. More precisely, sql developer does not show them, unless you call select * from name_table and then only through f5. Otherwise, he does not show information. What should I do to have SQL developer output table data again?
If anyone has faced such a problem, please tell me!
Such a script should have been originally:
CREATE TABLE "SPISOK_DOLGNOSTY"
( "KOD_DOLGN" NUMBER(*,0),
"NAME_DOLGN" VARCHAR2(50 BYTE)
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
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 "USERS" ;
REM INSERTING into SPISOK_DOLGNOSTY
SET DEFINE OFF;
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (1,'Директор предприятия');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (2,'Ведущий инженер');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (5,'Доцент');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (9,'Канцелярист');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (12,'Начальник отдела кадров');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (20,'Старший преподаватель');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (21,'Техник первой категории');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (118,'Сантехник');
Insert into SPISOK_DOLGNOSTY (KOD_DOLGN,NAME_DOLGN) values (120,'Кадровик');
--------------------------------------------------------
-- DDL for Index SYS_C007193
--------------------------------------------------------
CREATE UNIQUE INDEX "SYS_C007193" ON "SPISOK_DOLGNOSTY" ("KOD_DOLGN")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "USERS" ;
--------------------------------------------------------
-- DDL for Index SYS_C007112
--------------------------------------------------------
CREATE UNIQUE INDEX "SYS_C007112" ON "SPISOK_DOLGNOSTY" ("NAME_DOLGN")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "USERS" ;
--------------------------------------------------------
-- Constraints for Table SPISOK_DOLGNOSTY
--------------------------------------------------------
ALTER TABLE "SPISOK_DOLGNOSTY" ADD UNIQUE ("NAME_DOLGN")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "USERS" ENABLE;
ALTER TABLE "SPISOK_DOLGNOSTY" ADD PRIMARY KEY ("KOD_DOLGN")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "USERS" ENABLE;
ALTER TABLE "SPISOK_DOLGNOSTY" MODIFY ("NAME_DOLGN" NOT NULL ENABLE);
enter image description here
enter image description here
enter image description here
enter image description here
Your DDL, used on a Oracle 12cR2 database, running in a more recent version of SQL Developer (20.0), works just fine.
Try:
restarting the application
check the log panel for errors
UPGRADE your software, it's free and just a simple UnZip and go

Oracle 12C: Insert script takes too much time after truncate

We have a production environment with Oracle 12C. It has two instances and is using Oracle Data Guard to have a replica in another server.
Every time that we release a new version, we have to truncate some tables, which doesn’t have any index, and execute several scripts with inserts statements like this one:
ALTER TABLE T_I18N DISABLE ALL TRIGGERS;
TRUNCATE TABLE T_I18N;
INSERT INTO T_I18N VALUES ('sp', 'Table 1', '0', 'Tabla 1');
INSERT INTO T_I18N VALUES ('sp', 'Table 2', '0', 'Tabla 2');
INSERT INTO T_I18N VALUES ('sp', 'Table 3', '0', 'Tabla 3');
.
.
ALTER TABLE HIS_I18N ENABLE ALL TRIGGERS;
Previously, we also have disabled all the primary keys and foreign keys. To give more information, the table structure is the following one:
CREATE TABLE "T_I18N"
("T_CODE" VARCHAR2(5 BYTE),
"T_KEY" VARCHAR2(200 BYTE),
"T_C_ID" NUMBER(6,0),
"T_VALUE" VARCHAR2(500 BYTE),
CONSTRAINT "HIN_PK" PRIMARY KEY ("T_CODE", "T_KEY", "T_C_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "TB1" ENABLE,
CONSTRAINT "HIN_CEN_FK" FOREIGN KEY ("T_C_ID")
REFERENCES "TB1"."T_CEN" ("T_C_ID") ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
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 "TB1";
The script with more Insert statements has about 20K and it takes about 12 minutes to be executed. In my opinion, it was taking too much time, so I took a different approach. I tried to drop the table, recreate it and then execute the script, and it took only 40 seconds.
I have been searching through Oracle website to understand why there are so much difference between drop/recreate and truncate, but unfortunately I couldn’t find any clue about it.
Thanks by advance. Any information or advice would be really appreciated.
Cheers!

What is the difference between defining the index as a primary key or in the CREATE INDEX clause?

I am testing a query with a table of 500 million records.
The field ID_COMPANY only has value 1 (500 millon records).
The SQL is defined as follows:
CREATE TABLE "BIDATA"."CSC_CUSTOMER_PREPAID_BALANCE"
( "ID_COMPANY" VARCHAR2(10 BYTE),
"SEQUENTIAL_MOV" NUMBER(10,0),
"ID_PAYMENT" NUMBER(10,0)
CONSTRAINT "PK_CSC_CUSTOMER_PREPAID_BAL" PRIMARY KEY ("ID_COMPANY", "SEQUENTIAL_MOV")
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 "BIDATA_DATOS" ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
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 "BIDATA_DATOS" ;
CREATE INDEX clause for the ID_PAYMENT field for example
CREATE INDEX "BIDATA"."IDX_ID_PAYMENT" ON "BIDATA"."CSC_CUSTOMER_PREPAID_BALANCE" ("ID_PAYMENT")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
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 "BIDATA_DATOS" ;
The problem that I have, that when launching a query as defined, it seems that it does not detect the index ID_COMPANY and it takes more than 15 minutes to show results, but if in the query in the WHERE clause I add ID_COMPANY = '1', it shows the results in less than 10 seconds.
Should I delete the index ID_COMPANY and define it as CREATE INDEX?
Why does that time difference occur?
SQL query takes> 10 minutes.
SELECT
COUNT(*)
FROM
CSC_CUSTOMER_ACCOUNT,
CSC_CUSTOMER_PREPAID_BALANCE
WHERE
AND ( CSC_CUSTOMER_ACCOUNT.ID_ACCOUNT(+)=CSC_CUSTOMER_PREPAID_BALANCE.ID_ACCOUNT AND CSC_CUSTOMER_ACCOUNT.ID_COMPANY(+)=CSC_CUSTOMER_PREPAID_BALANCE.ID_COMPANY )
AND ( CSC_CUSTOMER_PREPAID_BALANCE.ID_ACCOUNT (+)=CSC_RECHARGE_MOBILE.ID_ACCOUNT AND CSC_CUSTOMER_PREPAID_BALANCE.SEQUENTIAL_MOV(+)=CSC_RECHARGE_MOBILE.SEQUENTIAL_MOV )
SQL query takes < 10 seconds.
SELECT
COUNT(*)
FROM
CSC_CUSTOMER_ACCOUNT,
CSC_CUSTOMER_PREPAID_BALANCE
WHERE
AND ( CSC_CUSTOMER_ACCOUNT.ID_ACCOUNT(+)=CSC_CUSTOMER_PREPAID_BALANCE.ID_ACCOUNT AND CSC_CUSTOMER_ACCOUNT.ID_COMPANY(+)=CSC_CUSTOMER_PREPAID_BALANCE.ID_COMPANY )
AND ( CSC_CUSTOMER_PREPAID_BALANCE.ID_ACCOUNT (+)=CSC_RECHARGE_MOBILE.ID_ACCOUNT AND CSC_CUSTOMER_PREPAID_BALANCE.SEQUENTIAL_MOV(+)=CSC_RECHARGE_MOBILE.SEQUENTIAL_MOV )
AND CSC_CUSTOMER_PREPAID_BALANCE.ID_COMPANY = '1'
QUERY execution plan> 10 minutes
Execution plan Query > 10
Execution plan Query < 10 seconds
Thank you.
From what I can infer from your question, you seem to misinterpret the indexing rules for a table. Ideally you don't create an index for the primary key, rather it is the other way around. i.e. when you create a table with a primary key it(primary key) by default is considered as a clustered index by the sql agent and created/stored accordingly.
More on Indexing and Index types here

ORA-00911: invalid character - When running SQL dump

I have a bunch of SQL which I need to execute, but Oracle is complaining with this error:
Error Message : ORA-00911: invalid character
Position : 27
Statement : (dump below)
I'm not sure what's causing this. I have tried removing the semicolon at the end as some answers suggested, but that's not doing the trick. I'm attempting to run this SQL dump on Laravel 5.2 with the DB::unprepared() method, like so:
DB::connection('oracle')->unprepared(File::get(base_path('/path/to/oracle_dump.sql')));
This is the SQL I'm trying to run:
DROP TABLE "MYUSERNAME"."POSTS";
DROP SEQUENCE "MYUSERNAME"."POST_SEQ";
CREATE TABLE POSTS
(
ID NUMBER(*, 0) NOT NULL, TITLE VARCHAR2(1000 BYTE), CONSTRAINT SYS_C004109 PRIMARY KEY(ID)
USING INDEX
(
CREATE UNIQUE INDEX SYS_C004109 ON POSTS (ID ASC)
LOGGING
TABLESPACE TEST_TABLSPACE
PCTFREE 10
INITRANS 2
STORAGE
(
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
)
NOPARALLEL
)
ENABLE
)
LOGGING
TABLESPACE TEST_TABLSPACE
PCTFREE 10
INITRANS 1
STORAGE
(
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
)
NOPARALLEL
CREATE SEQUENCE POST_SEQ INCREMENT BY 1 MAXVALUE 9999999999999999999999999999 MINVALUE 1 CACHE 20
CREATE TRIGGER POST_BIR
BEFORE INSERT ON posts
FOR EACH ROW
BEGIN
SELECT post_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
I have used SQLDeveloper on Mac to get this dump.
You should use ";" after each statement in the file "oracle_dump.sql".
DROP TABLE "MYUSERNAME"."POSTS";
DROP SEQUENCE "MYUSERNAME"."POST_SEQ";
CREATE TABLE POSTS
(
ID NUMBER(*, 0) NOT NULL, TITLE VARCHAR2(1000 BYTE), CONSTRAINT SYS_C004109 PRIMARY KEY(ID)
USING INDEX
(
CREATE UNIQUE INDEX SYS_C004109 ON POSTS (ID ASC)
LOGGING
TABLESPACE TEST_TABLSPACE
PCTFREE 10
INITRANS 2
STORAGE
(
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
)
NOPARALLEL
)
ENABLE
)
LOGGING
TABLESPACE TEST_TABLSPACE
PCTFREE 10
INITRANS 1
STORAGE
(
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
)
NOPARALLEL;
CREATE SEQUENCE POST_SEQ INCREMENT BY 1 MAXVALUE 9999999999999999999999999999 MINVALUE 1 CACHE 20;
CREATE TRIGGER POST_BIR
BEFORE INSERT ON posts
FOR EACH ROW
BEGIN
SELECT post_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
Try executing each statement in a separate file, and do not close the statement with ";" once you have each in its file
You have 5 statement in the file "oracle_dump.sql". Have a separate file for each if you want to run them using a command like:
DB::connection('oracle')->unprepared(File::get(base_path('/path/to/<<file>>')));

`show create table` equivalent in oracle sql

In MySql you can see the table definition (columns with their data types etc) with show create table table_name.
Is there a similar functionality for oracle sql?
If you are asking about SQL*Plus commands (show create table table_name doesn't appear to be a SQL statement), you can use the desc command
SQL> desc emp
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
If you really want a SQL statement, you can use the dbms_metadata package
1 select dbms_metadata.get_ddl( 'TABLE', 'EMP', 'SCOTT' )
2* from dual
SQL> /
DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')
--------------------------------------------------------------------------------
CREATE TABLE "SCOTT"."EMP"
( "EMPNO" NUMBER(4,0),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0),
CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
ALTER INDEX "SCOTT"."PK_EMP" UNUSABLE ENABLE,
CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
CACHE
Depending on the tool you are using, you may need to run set long 10000 first, that tells SQL*Plus to display the first 10,000 bytes of any LOB that is selected. If your DDL is longer, set a larger value.
Use DESC:
DESC mytable
Will show you the columns, but unfortunately the create statement is not available using standard oracle tools.
SQL> set long 1000
SQL> set pagesize 0
SQL> select DBMS_METADATA.GET_DDL('TABLE','TABLE NAME'[,'SCHEMA']) from DUAL
If you are using PL/SQL Developer; Right click on table, Select View, at the right bottom of the view window click on 'View SQL' button.
Just a note that table name is case_sensitive, you need to pass in table name as upper case.
DDL is working for me and more simple all you need is to write DDL (SCHEMA_OWNER).(TABLE_NAME) ...for example ddl HR.LOCATIONS;....HR is the schema and LOCATION is table name ...make sure you write both the SCHEMA name and table NAME in capital here the output will be
CREATE TABLE "HR"."LOCATIONS"
( "LOCATION_ID" NUMBER(4,0),
"STREET_ADDRESS" VARCHAR2(40),
"POSTAL_CODE" VARCHAR2(12),
"CITY" VARCHAR2(30) CONSTRAINT "LOC_CITY_NN" NOT NULL ENABLE,
"STATE_PROVINCE" VARCHAR2(25),
"COUNTRY_ID" CHAR(2),
CONSTRAINT "LOC_ID_PK" PRIMARY KEY ("LOCATION_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE
STATISTICS
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,
CONSTRAINT "LOC_C_ID_FK" FOREIGN KEY ("COUNTRY_ID")
REFERENCES "HR"."COUNTRIES" ("COUNTRY_ID") ENABLE
) SEGMENT CREATION IMMEDIATE
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" ;
COMMENT ON COLUMN "HR"."LOCATIONS"."LOCATION_ID" IS 'Primary key of
locations table';
COMMENT ON COLUMN "HR"."LOCATIONS"."STREET_ADDRESS" IS 'Street address
of an office, warehouse, or production site of a company.
Contains building number and street name';
COMMENT ON COLUMN "HR"."LOCATIONS"."POSTAL_CODE" IS 'Postal code of
the
location of an office, warehouse, or production site
of a company. ';
COMMENT ON COLUMN "HR"."LOCATIONS"."CITY" IS 'A not null column that
shows city where an office, warehouse, or
production site of a company is located. ';
COMMENT ON COLUMN "HR"."LOCATIONS"."STATE_PROVINCE" IS 'State or
Province where an office, warehouse, or production site of a
company is located.';
COMMENT ON COLUMN "HR"."LOCATIONS"."COUNTRY_ID" IS 'Country where an
office, warehouse, or production site of a company is
located. Foreign key to country_id column of the countries table.';
COMMENT ON TABLE "HR"."LOCATIONS" IS 'Locations table that contains
specific address of a specific office,
warehouse, and/or production site of a company. Does not store
addresses /
locations of customers. Contains 23 rows; references with the
departments and countries tables. ';
CREATE INDEX "HR"."LOC_CITY_IX" ON "HR"."LOCATIONS" ("CITY")
PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS
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" ;
CREATE INDEX "HR"."LOC_COUNTRY_IX" ON "HR"."LOCATIONS" ("COUNTRY_ID")
PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS
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" ;
CREATE INDEX "HR"."LOC_STATE_PROVINCE_IX" ON "HR"."LOCATIONS"
("STATE_PROVINCE")
PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS
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" ;