toad for oracle alter table ddl export - oracle

I use Toad for Oracle v12.6 and able to see DDL export for full table under the Database menu.
Does anyone know is it possible to generate DDL for spesific columns of a table?
With an example; I have table Employees with 5 columns like:
EmpID INTEGER,
Name VARCHAR2(100),
SurName VARCHAR2(100),
Age INTEGER,
Address VARCHAR2(200)
I want to generate alter script for Age and Address columns only using Toad for Oracle.
Edit: I do not want to alter the table, I want to have an "alter table add column Age and Address with datatypes" script as below;
ALTER TABLE Employees ADD Age Integer;
ALTER TABLE Employees ADD Address VARCHAR2(200);
Any help would be appropriated.

yes you can do it just with toad
first you should click alter table:
then you can modify

Related

Apex Oracle How To Create Conditional Column

I am new to using Apex Oracle to create a table and insert values in it. I need to create a column that is only mandatory if the value for another column is "Y" (if it is "N", then it is not mandatory). The type of the other column is a CHAR with length 1. How could I do this? Would this be done in SQL Scripts or SQL Commands? Similarly, is there a way to delete old SQL commands that were used (that now I realize are incorrect)?
Thank you!
Welcome to Oracle APEX and Stack Overflow. You can create objects (tables/views) in both SQL commands and SQL Scripts. For ad hoc creating, SQL Commands is probably easier. To remove (called "drop" in oracle) objects that you create, that can be done in SQL Commands, or even easier in the "Object Browser" - locate the object and select "drop". Note that this cannot be undone.
About the requirement for a column to be conditionally mandatory:
This can be enforced in the database using a check constraint.
CREATE TABLE test_table (
id NUMBER GENERATED AS IDENTITY,
col1 VARCHAR2(1),
col2 VARCHAR2(10));
Table TEST_TABLE created.
ALTER TABLE test_table ADD CONSTRAINT test_table_c1
CHECK ((col1 = 'Y' AND col2 IS NOT NULL) or (col1 != 'Y'));
Table TEST_TABLE altered.
INSERT INTO test_table(col1,col2) VALUES ('N',NULL);
1 row inserted.
INSERT INTO test_table(col1,col2) VALUES ('Y',NULL);
INSERT INTO test_table(col1,col2) VALUES ('Y',NULL)
Error report -
ORA-02290: check constraint (SAMPLEAPPS.TEST_TABLE_C1) violated
INSERT INTO test_table(col1,col2) VALUES ('Y','Some Value');
1 row inserted.

Invalid ALTER TABLE option ORA-01735

I'm looking to add an identity column to my existing table in oracle apex, but I am being given the invalid ALTER TABLE option error. I've been searching through a lot of threads about this error but I couldn't seem to find anything helpful for this particular problem.
ALTER TABLE tbl_Customer
ADD Customer_ID int Identity(1,1);
I'd appreciate a link to any posts that may be useful, thanks for taking a look.
Wrong syntax. Should be
SQL> create table tbl_customer (name varchar2(20));
Table created.
SQL> alter table tbl_customer add customer_id int generated always as identity;
Table altered.
SQL>
Besides, you are NOT using MySQL as you got ORA-01735 error (which is related to Oracle).

How to find the root cause of ORA-54033 error when altering column data type

I am attempting to alter the data type of a column from a NUMBER to a VARCHAR2 in an existing database table. When running the following ALTER TABLE statement I receive the "ORA-54033: column to be modified is used in a virtual column expression" error:
ALTER TABLE table MODIFY (col1 varchar2(8));
I have already worked through the directions listed here. When looking at the SYS generated export statistics using the following query
select column_name, data_default, hidden_column
from user_tab_cols
where table_name = 'Table';
there is nothing referencing col1 in export statistics. There are about 15 hidden, SYS generated rows associated with the table and they all have a data default value of <Long>. There are no virtual columns in the DDL, nor is this column being used for any indexes or as a FK. I have also had the DBA run the following:
SELECT EXTENSION_NAME, EXTENSION, CREATOR, DROPPABLE
FROM DBA_STAT_EXTENSIONS
WHERE TABLE_NAME='Table'
and the output lines up with what I find in user_tab_cols. Where else can I look for this seemingly buried virtual column?

Oracle: Changing VARCHAR2 column to CLOB

I have an encountered an issue where the data I was trying to store in my varchar2(4000) column was too big, so I wish to change the column to one more suitable for storing large amounts of textual data. Specifically, a serialized array.
Firstly, is CLOB the best data type for me to use for this purpose? Is there a more appropriate data type?
Secondly, when I try to alter the column using the usual snyntax:
ALTER TABLE table MODIFY column CLOB
I get the following error: ORA-22858: invalid alteration of datatype
What's the most straightforward way to alter this table without losing any data?
The most straightforward way, given that the operation of moving from a varchar column to a CLOB is disallowed, would be to create a new column and move the data from the old column to the new column:
ALTER TABLE some_table ADD (foo CLOB);
UPDATE some_table SET foo = old_column;
ALTER TABLE some_table DROP COLUMN old_column;
ALTER TABLE some_table RENAME COLUMN foo TO old_column;
The VARCHAR2 column cannot be directly converted to CLOB but it can be done in 2 steps:
Convert column datatype from VARCHAR2 to LONG.
Convert column datatype from LONG to CLOB.
ALTER TABLE table MODIFY column long;
ALTER TABLE table MODIFY column clob;
For Oracle 11g:
ALTER TABLE table MODIFY column long;
ALTER TABLE table MODIFY column clob;

Automatically populate date in oracle table

I have created a table in oracle XE, and I have a field with type date. I would like if possible when I insert a row, that it automatically fills that field with the current date from the system.
I am inserting the rows from the SQL prompt.
Thanks
Here is how, you need to format your table properly:
create table test (first number
, second timestamp default systimestamp
, third varchar2(12));
And your default value is always current system time formatted as timestamp.
change the field after creating the table
ALTER TABLE table MODIFY time_collumn TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
Or you could also use a trigger:
CREATE OR REPLACE TRIGGER date_trigger
BEFORE INSERT
ON table_name
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT sysdate INTO :NEW.column_name FROM dual;
END;
The below snippet might be helpful if we forget to add the constraint while creating the table:
ALTER TABLE TABLE_NAME
ADD CONSTRAINT CONSTRAINT_NAME
COLUMN_NAME DATA_TYPE DEFAULT CURRENT_DATE;

Resources