What is the similar syntax for create or replace view(which exists in RDBMS) in hive.
For example,
Create or replace view as select * from table1.
I know there is syntax create if not exists.
But in my case, view exists in lower environment, so i want to replace and view if doesn't in higher environment , i need to create.
Since i need to do source-code once and deploy in all environments. I need similar code to create or replace view.
Can someone please help?
CREATE OR REPLACE VIEW
feature was introduced in Hive 0.8 in Jira HIVE-1078
Also there is ALTER VIEW as SELECT as of Hive 0.11 (View must exist)
ALTER VIEW [db_name.]view_name AS select_statement;
On Hive version < 0.8 and if upgrade is not possible use DROP+CREATE
DROP VIEW [IF EXISTS] [db_name.]view_name;
CREATE VIEW [db_name.]view_name ...
Related
Oracle EBS R12.2.9
I have to add a new column to an editioning view of a custom table in oracle EBS R12.2.9.
Table was created like this...
From AMTO: create table amto.mci_jjtest1(a number)
From APPS: exec ad_zd_table.upgrade('AMTO', 'MCI_JJTEST1') -- This creates editioning view and also synonym under APPS
Now, new column B number with data type, needs to be added to the table, and the editioning view needs to be modified to add that column to the editioning view. Kindly let me know what commands and steps, I need to follow. I understand the traditional approach, where we would alter table to add column, and create or replace view to add the column to the SELECT, Not sure how to add column to table and editioning view the correct recommended way. Please suggest.
For table alterations - after running the DDL run below script to regenerate the editioning view for syncing any table changes.
exec AD_ZD_TABLE.PATCH('AMTO','MCI_JJTEST1')
I am working on some Enterpriseware backed by an Oracle 11.2 database. The enterpriseware has some table named T in its datamodel. I found a table named OLDT along in this datamodel, probably created by some script run in production by the previous maintainers. This OLDTtable has a trigger TRIG associated to it, which was clearly intended to be attached to T, and is coded in the style of the enterpriseware. I suspect this is the result of some script renaming T to OLDT, and recreating T after that.
My question is : is there a direct way, in Oracle, to retarget a trigger to another table, or is dropping and recreating the trigger the standard way to do this?
Following this thread, you can view a source code of your trigger. Then copy its source code, change what you need to change in it (table name), drop existing trigger and create a new one.
From the thread, try this:
select dbms_metadata.get_ddl('TRIGGER','MY_TRG',user)
from dual;
or this
select text
from all_source
where name='&trig_name' and type='TRIGGER';
An external system granted to my system a view named V_EXT so that I can make selections on it, reading all its content:
SELECT *
FROM V_EXT;
this view has a lot of fields and I would like to create an empty table in my system with the exactly same attributes of this view (same names and same types). Is there a way to do this without simply guessing from the content I received what each attribute is?
I am using Oracle SQL Developer.
With Code.
create table objects_copy2
as
select *
from all_objects
where 1=2; -- add this line if you want NO data, otherwise you get all the data too
With SQL Developer specifically, it's actually harder. You would need to find the underlying OBJECT(s) used in the query. Then look up those data types, and manually build out your CREATE TABLE statement.
CREATE TABLE AS SELECT is the way to go. (Docs)
Note there are some limitations, for example this won't pick up Identity Column definitions from the source table used in the view.
An example:
I want to create a table (lets say table_copy) which has same columns as other table (lets call it table_original) in Oracle database, so the query will be like this :
create table table_copy as (select * from table_original where 1=0);
This will create a table, but the constraints of table_original are not copied to table_copy, so what should be done in this case?
Only NOT NULL constraints are copied using Create Table As Syntax (CTAS). Others should be created manually.
You might however query data dictionary view to see the definitions of constraints and implement them on your new table using PL/SQL.
The other tool that might be helpful is Oracle Data Pump. You could import the table using REMAP_TABLE option specifying the name for the new table.
Use a database tool to extract the DDL needed for the constraints (SQL Developer does the job). Edit the resulting script to match the name of the new class.
Execute the script.
If you need to do this programmatically you can use a statement like this:
DBMS_METADATA.GET_DDL('TABLE','PERSON') from DUAL;
I've made some changes to columns in a database table (increasing the size of varchar), however I need to have the view of the table refreshed to pick up this change. In SQL server 2005 I would use the script to -> alter to recreate the script for the view. I'm trying to figure out what the Oracle SQL command would be to rebuild the view to display the change of the column?
Unless your view is explicitly restricting the size of the column, it will pick up the change automatically. It may have been invalidated by the table change but would be automatically recompiled when first used; or can be manually recompiled with alter view <view name> compile.
If you do so:
create table sample_table(text varchar2(10));
insert into sample_table (text) values('text...');
create view sample_view as select * from sample_table;
select * from sample_view;
alter table sample_table modify text varchar2(200);
You do not do anything to promote this change in view in Oracle database.
Or you can use "ALTER VIEW sample_view COMPILE" (how wrote #AlexPole or #devio). Oracle do this automatically when you firstly use select on sample_view after alter table.
Try
ALTER VIEW MyView COMPILE;