跨数据库查询语句 OPENQUERY 带参数||查ORACLE数据库||时间转换

---------------------------------------OPENQUERY------------------------------------------------------------------------

普通:写的时候一定要注意里面没有冒号;


SELECT * FROM OPENQUERY([10.11.7.112],'select to_date(''2012-06-18 00:00:00'',''yyyy-mm-dd hh24:mi:ss'')  from dual')

带参数的话,网上看到的example:
亲测可用

DECLARE @Sql VARCHAR(1000)
DECLARE @organizationID VARCHAR(10)
SELECT @organizationID = (SELECT ORGANIZATION_ID FROM MYORGS WHERE ORGANIZATION_NAME = 'MMT')
SET @Sql = 'SELECT * from tableName where organization_id ='+@organizationID 
SET @Sql = 'SELECT * FROM OPENQUERY(LinkedServerName, ''' + REPLACE(@Sql, '''', '''''') + ''')'
EXEC(@Sql)

---------------------------------------ORACLE数据库查询语句------------------------------------------------------------------------

1. 按某列最大排序  查第一条(示例中列名为UPDATETIME)

SELECT MAX(UPDATETIME) FROM IHIS.ZD_I

2.字符串转时间

date 的

select to_date(''2012-06-18 00:00:00'',''yyyy-mm-dd hh24:mi:ss'')  from dual

 

timestamp的 (可以到秒后3位,date只能到秒

select to_timestamp(''2003-10-24 10:48:45.656000'',''yyyy-mm-dd hh24:mi:ssxff'') from dual

 

你可能感兴趣的:(数据库查询语句)