I'm trying to create the following table:
CREATE TABLE helpToolStatsTest (
customer nvarchar2(25),
data nvarchar2(7),
myDate Date NOT NULL DEFAULT CURRENT_DATE()
)
but I'm getting this error:
ORA-00907: missing right parenthesis
According to the documentation:
CREATE TABLE helpToolStatsTest (
customer nvarchar2(25),
data nvarchar2(7),
myDate Date DEFAULT CURRENT_DATE NOT NULL
)
Related
I'm trying to create a table named MEMBER. The datatype for REGISTERDATE is DATE and the default value is SYSDATE. There is another column named EXPIRYDATE, datatype is DATE and the default value is 1 year after SYSDATE. So how am I going to create for the column of EXPIRYDATE when creating the table definition?
I tried REGISTERDATE DATE DEFAULT SYSDATE,
EXPIRYDATE DATE + 365,
It showed error..
You're so close, you're just missing the default keyword and sysdate after expirydate date
-
create table MEMBER (
REGISTERDATE date default sysdate,
expirydate date default sysdate+365
)
test:
insert into MEMBER(REGISTERDATE) values (sysdate)
output:
Not all years have 365 days; on average, only 3 out of 4. But you can literally define an expression that expresses "1 year after":
create table member (
id number(*,0) not null primary key,
registerdate date default sysdate,
expirydate date default sysdate + interval '1' year
);
Remember that Oracle won't use the default value if you provide your own, even if it's null. You need to complete omit the field from the INSERT INTO statement.
Demo
Created database scoped credential and an external datasource to Oracle OK.
Creating external table on Orcle table with a column datatype TIMESTAMP WITH TIME ZONE fails no matter what datatype I try to use.
CREATE EXTERNAL TABLE MYSCHEMA.MY_EXT_TABLE
(
SOMECOL NVARCHAR(21) COLLATE Finnish_Swedish_BIN, -- OK
SOME_DATETIME DATETIME2, -- OK
SOME_DATE_COMM DATE,-- OK
SOME_FLOAT float,-- OK
SOME_TIMESTAMP datetimeoffset(7) -- NOK
)
WITH
(
LOCATION = N'ORACLEDATABASE.SCHEMA.TABLE',
DATA_SOURCE = my_oracle_ds
)
GO
Fails with error:
Msg 105083, Level 16, State 1, Line 2
105083;The following columns in the user defined schema are incompatible with the external table schema for table 'SOME_TABLE': 'SOME_TIMESTAMP' failed to be reflected with the error: 'The detected backend type TIMESTAMP(6) WITH TIME ZONE is not supported for external generic tables.'
I tried with datetime, datetime2, datetimeoffset, NVARCHAR but the same error occurs.
Is there a workaround for polybase/generic tables or do I have to skip these columns?
CREATE EXTERNAL TABLE MYSCHEMA.MY_EXT_TABLE
(
SOMECOL NVARCHAR(21) COLLATE Finnish_Swedish_BIN,
SOME_DATETIME DATETIME2,
SOME_DATE_COMM DATE,
SOME_FLOAT FLOAT,
SOME_TIMESTAMP TO_TIMESTAMP_TZ('America/Los_Angeles', 'TZR')
) WITH ( LOCATION = N'ORACLEDATABASE.SCHEMA.TABLE' , DATA_SOURCE = my_oracle_ds ) GO
I have a table named masterregistry and it contains all the info and business logic in it and the data type of the colum is clob
desc master_registy:
id number not null,
name varchar2(100),
value clob
select value from master_registry where name='REG_DATE';
o/p
11-10-17
This date is common across all the business logic, I need to query my tables which has ,
desc get_employee
====================
id number not null,
first_name varchar2(100),
last_name varchar2(100),
last_mod_dt timestamp
Now I need to get all the values from the get_employee whose last_mod_dt should be greater than the value of master_registry where name='REG_DATE'.The value in the latter table is clob data, how to fetch and compare the date of a clob data against the timestamp from another table. Please help.
Maybe you need something like this.
SELECT *
FROM get_employee e
WHERE last_mod_dt > (SELECT TO_TIMESTAMP (TO_CHAR (VALUE), 'DD-MM-YY')
FROM master_registy m
WHERE m.id = e.id);
DEMO
Note that i have used the column value directly in TO_CHAR. You may have to use TRIM,SUBSTR or whatever required to get ONLY the date component.
Hey I have two columns in my HIVE table :
For example :-
c1 : name
c2 : age
Now while creating a table I want to declare two more columns which automatically give me the current date and time when the row is loaded.
eg: John 24 26/08/2015 11:15
How can this be done?
Hive currently does not support the feature to add a default value to any column definition while creating a table. Please refer to the link for complete hive create table syntax:
Hive Create Table specification
Alternative work around for this issue would be to temporarily load data into temporary table and use the insert overwrite table statement to add the current date and time into the main table.
Below example may help:
1. Create a temporary table
create table EmpInfoTmp(name string, age int);
2. Insert data using a file or existing table into the EmpInfoTmp table:
name|age Alan|28 Sue|32 Martha|26
3. Create a table which will contain your final data:
create table EmpInfo(name string, age tinyint, createDate string, createTime string);
4. Insert data from the temporary table and with that also add the columns with default value as current date and time:
insert overwrite table empinfo select name, age, FROM_UNIXTIME( UNIX_TIMESTAMP(), 'dd/MM/YYYY' ), FROM_UNIXTIME( UNIX_TIMESTAMP(), 'HH:mm' ) from empinfofromfile;
5. End result would be like this:
name|age|createdate|createtime Alan|28|26/08/2015|03:56 Martha|26|26/08/2015|03:56 Sue|32|26/08/2015|03:56
Please note that the creation date and time values will be entered accurately by adding the data to your final table as and when it comes into the temp table.
Note: You can't set more then 1 column as CURRENT_TIMESTAMP.
Here this way, You cant set CURRENT_TIMESTAMP in one column
SQL:
CREATE TABLE IF NOT EXISTS `hive` (
`id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`age` int(11) DEFAULT '0',
`datecreated` timestamp NULL DEFAULT CURRENT_TIMESTAMP
);
Hey i found a way to do it using shell script.
Heres how :
echo "$(date +"%Y-%m-%d-%T") $(wc -l /home/hive/landing/$line ) $dir " >> /home/hive/recon/fileinfo.txt
Here i get the date without spaces. In the end I upload the textfile to my hive table.
I am trying to create a table that has a default value for a date that is sysdate - 2 in oracle
Oracle seems to be fine with sysdate as the default but not sysdate - 2. Is this possible?
You need to specify the DEFAULT value in brackets:
Create the table:
CREATE TABLE order_status (
order_id NUMBER,
last_modified DATE DEFAULT (SYSDATE - 2)
);
Insert a record to test the default:
INSERT INTO order_status
(order_id)
VALUES
(1);
Select the data from the table to confirm the default worked (Current date 14/11/2011):
SELECT *
FROM order_status;
ORDER_ID LAST_MODIFIED
1 12/11/2011
DB Version 10g.
Hope it helps...