--Generate SQL script adding your descriptions from Dataedo to coment fields in Oracle DB
--Edit @title and run this in your Dataedo repository.
--Then copy results of the statement and run those in your actual database.

--Put title of your documentation here (should be unique)
DECLARE @title AS NVARCHAR(250) = 'dataedo repository';
--ORACLE
--table descriptions
SELECT CONCAT (
		'COMMENT ON TABLE '
		,tbl.[schema]
		,'.'
		,tbl.[name]
		,' IS '''
		,replace(left(tbl.[description_search], 4000), '''', '''''')
		,''';'
		) AS oracle_sql_command
FROM dbo.[tables] tbl
INNER JOIN dbo.[databases] db
	ON db.database_id = tbl.database_id
WHERE tbl.[description_search] IS NOT NULL
	AND tbl.[status] = 'A'
	AND db.[title] = @title
--column descriptions
UNION ALL
SELECT CONCAT (
		'COMMENT ON COLUMN '
		,tbl.[schema]
		,'.'
		,tbl.[name]
		,'.'
		,col.[name]
		,' IS '''
		,replace(left(col.[description], 4000), '''', '''''')
		,''';'
		) AS oracle_sql_command
FROM dbo.[tables] tbl
INNER JOIN dbo.[columns] col
	ON col.table_id = tbl.table_id
INNER JOIN dbo.[databases] db
	ON db.database_id = tbl.database_id
WHERE col.[description] IS NOT NULL
	AND tbl.[status] = 'A'
	AND col.[status] = 'A'
	AND db.[title] = @title;