I want to insert json record to oracle table with Nifi and some of the columns type in table are timestamp. how can I determine timestamp columns in sql statement.
here is the output of processor:
here is table schema:
here is timestamp format in content:
"timestamp": "Mon, 04.04.2022 02:17:09"
Perhaps something like this can help you out. You can add to the not in clause as needed.
select col.owner as schema_name,
col.table_name,
column_id,
column_name,
data_type,
data_scale as second_scale
from sys.dba_tab_cols col
join sys.dba_tables tab on col.owner = tab.owner
and col.table_name = tab.table_name
where (data_type in ('DATE')
or col.data_type like 'TIMESTAMP%'
or col.data_type like 'INTERVAL%')
and col.owner not in ('SYS','SYSTEM')
order by col.owner,
col.table_name,
column_id;
Related
The following mysql query returns the constraints and the default values along with column_name, is_null and other details -
mysql query - select TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLUMN_TYPE, COLUMN_KEY, EXTRA from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'DB_NAME'
I want to write a similar query in Oracle, the following query returns data_type and is_null but doesn't return constraints and default values -
Oracle query - SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, NULLABLE FROM DBA_TAB_COLUMNS where owner = 'USERNAME'
How can I extract those information from an oracle table.
Note: I don't want to use describe table
Select tc.TABLE_NAME, tc.COLUMN_NAME, tc.DATA_TYPE, tc.NULLABLE, tc.DATA_DEFAULT,
con.cons
from DBA_TAB_COLUMNS tc
left join
( select listagg( cc.constraint_name, ',') within group (order by cc.constraint_name) cons,
table_name, owner , column_name
from DBA_CONS_COLUMNS cc
group by table_name, owner , column_name ) con
on con.table_name = tc.table_name and
con.owner = tc.owner and
con.column_name = tc.column_name
where tc.owner = 'USERNAME'
order by 1 ,2
There can be multiple constraints (or none) for each column. Because of that left join is used and listagg function to display all constraint in one column.
TABLE_NAME COLUMN_NAME DATA_TYPE NULLABLE DATA_DEFAULT CONS
AQ$_QUEUE_TABLES OBJNO NUMBER N AQ$_QUEUE_TABLES_PRIMARY,SYS_C001643
AQ$_QUEUE_TABLES SCHEMA VARCHAR2 N SYS_C001640
AQ$_QUEUE_TABLES SORT_COLS NUMBER N SYS_C001645
AQ$_QUEUE_TABLES TABLE_COMMENT VARCHAR2 Y
AQ$_QUEUE_TABLES TIMEZONE VARCHAR2 Y
You can still try to use this below snippet to get the requested details. Hope this helps.
Note : This is for indexed columns as I thought you might need this too
SELECT DISTINCT col.owner,
col.table_name,
col.DATA_TYPE,
Col.Column_Name,
DECODE(nullable,'Y','Yes','N','No') nullable,
high_value(col.table_name,col.column_name), -- This is own created function to deal with LONG datatype columns
Ind.Index_Name
FROM SYS.All_Tab_Cols col,
All_Ind_Columns ind
WHERE Col.Table_Name = Ind.Table_Name
AND Col.Column_Name = Ind.Column_Name(+)
AND Col.Table_Name = UPPER('<TABLE_NAME>')
AND Col.Owner = '<SCHEMA_NAME>';
I have a column with TIMESTAMP type in my Oracle Database. The default column value is SYSTIMESTAMP.
I want to SELECT milliseconds FROM the TIMESTAMP column. I use the query below without success:
SELECT TO_CHAR (MY_TIMESTAMP, 'dd-mm-yyyy hh24:mi:ss.FF') AS MY_TIMESTAMP
FROM MY_TABLE
-- Result: 20-12-2015 15:23:28.
As you see the result does not have any milliseconds and it is empty. If I change the query with .FF4 then it results .0000.
How can I SELECT the column with milliseconds?
The precision for timestamp columns can be set up by
TIMESTAMP [(fractional_seconds_precision)].
In your case for 4 it's:
create table my_table
(id number,
my_TIMESTAMP timestamp(4) default SYSTIMESTAMP);
You can check your current precision by:
select column_name, data_scale from user_tab_columns
where table_name = 'MY_TABLE' and column_name = 'MY_TIMESTAMP';
Here is sample in SQL Fiddle
The display can be change by:
alter session set NLS_TIMESTAMP_FORMAT = 'DD-MON-RRRR HH:MI:SS.FF9';
I have around 1000 table out of which I need to list out the table names having clob or blob or lob containing columns. Is there any query to list out the same from my schema?
Try like this,
SELECT DISTINCT table_name
FROM user_tab_cols
WHERE data_Type IN ('CLOB', 'LOB', 'BLOB');
Try this one:
SELECT OWNER, TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM ALL_TAB_COLUMNS
WHERE DATA_TYPE IN ('CLOB', 'BLOB');
I havent a database handy, but this should work:
select * from ALL_TAB_COLUMNS a where a.DATA_TYPE in ('CLOB','BLOB','NCLOB','BFILE');
(see: http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2094.htm and http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm)
I want to know how to get total number of columns, individual column name and its corresponding data type in oracle. For example
SQL := 'SELECT UT.TABLESPACE_NAME, UT.TABLE_NAME, UT.STATUS, UT.NUM_ROWS, UT.LAST_ANALYZED,
(select count(1) from USER_TAB_COLS utc where utc.table_name = UT.TABLE_NAME) column_count
from USER_TABLES ut;'
then procedure should be able to display following information:
Total columns = 6
Column-1: TABLESPACE_NAME
Data type: Varchar2
Column-2: TABLE_NAME
Data type: Varchar2
Column-3: STATUS
Data type: Varchar2
Column-4: NUM_ROWS
Data type: Numeric
Column-5: LAST_ANALYZED
Data type: DATE
Column-6: COLUMN_COUNT
Data type: Numeric
If we change the SQL then result should be changed accordingly.
SELECT UT.TABLESPACE_NAME
, UT.TABLE_NAME
, UT.STATUS
, UT.NUM_ROWS
, UT.LAST_ANALYZED
, utc.column_name
, utc.data_type
, utc.data_length
, column_id ColumnNo
, max(utc.column_id) over (partition by ut.table_name) NoColumns
from USER_TABLES ut
inner join USER_TAB_COLS utc
on utc.table_name = ut.table_name
order by ut.tablespace_name
, ut.table_name
, utc.column_id
;
I use query:
select LAST_LOAD_TIME, ELAPSED_TIME, MODULE, SQL_TEXT elasped from v$sql
WHERE MODULE='JDBC Thin Client'
ORDER BY LAST_LOAD_TIME DESC
elasped:
delete from tableA where fk in (select pk from tableB where tableB.fk=:1
and tableB.date between :2 and :3)
Is it possible find these parameters 1, 2 and 3?
Something like this:
select s.sql_id,
bc.position,
bc.value_string,
s.last_load_time,
bc.last_captured
from v$sql s
left join v$sql_bind_capture bc
on bc.sql_id = s.sql_id
and bc.child_number = s.child_number
where s.sql_text like 'delete from tableA where fk%' -- or any other method to identify the SQL statement
order by s.sql_id, bc.position;