I run this query to get  the result like below, but even though my query is running fine I dont get the expected result.

I am looking for only column compare for making my target table same as source table.
My query:
select case when column_name_s is null and column_name_t is not null
            then 'alter table GRADE_CONVERSION drop ' || column_name_t || ';'
            when column_name_s is not null and column_name_t is null
            then 'alter table GRADE_CONVERSION add ' || column_name_s || ' ' || data_type_s ||';'
            else 'alter table GRADE_CONVERSION modify ' || column_name_t || ' ' || data_type_t ||';'
       end alterations
  from (select s.column_name column_name_s,t.column_name column_name_t,
               s.data_type data_type_s,t.data_type data_type_t
          from (select column_id,column_name,data_type
                  from all_tab_cols@database
                 where owner = 'erhan'
                   and table_name = 'GRADE_CONVERSION'
               ) s
               full outer join
               (select column_id,column_name,data_type
                  from all_tab_cols@database
                 where owner = 'sarigul'
                   and table_name = 'GRADE_CONVERSION'
               ) t
            on s.column_name = t.column_name
Tables:
Target table:         GRADE_CONVERSION table in sarigul@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
Source table:       GRADE_CONVERSION table in erhan@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
CREATED_BY
VARCHAR2(30)
CREATED_DATE
DATE
MODIFIED_BY
VARCHAR2(30)
MODIFIED_DATE
DATE
want to see the result similar to this *(please ignore the column names here this is just a plain exemple:)
Alter table Target_table modify BOOK_ID Varchar2 (4);
Alter table Target_table add ISBN_10 Varchar2(13), null;
Alter table Target_table drop TITLE;

I am looking for only column compare for making my target table same as source table.
My query:
select case when column_name_s is null and column_name_t is not null
            then 'alter table GRADE_CONVERSION drop ' || column_name_t || ';'
            when column_name_s is not null and column_name_t is null
            then 'alter table GRADE_CONVERSION add ' || column_name_s || ' ' || data_type_s ||';'
            else 'alter table GRADE_CONVERSION modify ' || column_name_t || ' ' || data_type_t ||';'
       end alterations
  from (select s.column_name column_name_s,t.column_name column_name_t,
               s.data_type data_type_s,t.data_type data_type_t
          from (select column_id,column_name,data_type
                  from all_tab_cols@database
                 where owner = 'erhan'
                   and table_name = 'GRADE_CONVERSION'
               ) s
               full outer join
               (select column_id,column_name,data_type
                  from all_tab_cols@database
                 where owner = 'sarigul'
                   and table_name = 'GRADE_CONVERSION'
               ) t
            on s.column_name = t.column_name
Tables:
Target table:         GRADE_CONVERSION table in sarigul@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
Source table:       GRADE_CONVERSION table in erhan@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
CREATED_BY
VARCHAR2(30)
CREATED_DATE
DATE
MODIFIED_BY
VARCHAR2(30)
MODIFIED_DATE
DATE
want to see the result similar to this *(please ignore the column names here this is just a plain exemple:)
Alter table Target_table modify BOOK_ID Varchar2 (4);
Alter table Target_table add ISBN_10 Varchar2(13), null;
Alter table Target_table drop TITLE;

Similar Messages

Maybe you are looking for