SQL 与 oracle 数据库链接插入数据。100分
本帖最后由 vobright 于 2012-11-18 20:15:45 编辑
本地为SQL环境,已经安装oracle,并做好配置。链接oracle 名 为HIS oracle ip 192.168.1.10 数据库ncdb 用户hisdb 密码 123
现有SQL链接的 存储过程,需要改为链接到oracle的语法
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER proc Auto_update_charge
AS
update A set A.名称=left(B.inv_name,16),
A.规格=left(B.inv_model,8),
A.单价=B.retail_price,
A.日期=convert(varchar(8),getdate(),112),
A.备注='后勤材料',
A.状态='0',
A.输入码=left(b.spell,10)
from [192.168.1.18,1433].fghisdb.dbo.代码_收费项目接口表 A,mate_inv_dict B
where A.代码=B.inv_code
and b.is_charge = '1' and isnull(b.edate,'')=''
and isnull(B.retail_price,0)<>0
and (b.update_date=convert(varchar(8),getdate(),112) or b.add_date=convert(varchar(8),getdate(),112))
insert into [192.168.1.18,1433].fghisdb.dbo.代码_收费项目接口表
(类别, 代码, 名称, 规格, 单位, 单价, 报销标志, 输入码, 医保代码, 医保名称, 部门, 科室,
日期, 备注, 状态)
select case when mate_type_code in('0805','0806','0810','0811','0812') then '47' else '13' end 类别,inv_code 代码,left(inv_name,16) 名称,left(inv_model,8) 规格,
(select max(unit_name) from sys_unit where a.unit_code=unit_code) 单位,retail_price 单价,case when mate_type_code in ('0805','0806','0810','0811','0812') then '0' else '1' end 报销标志,
left(spell,10) 输入码,' ' 医保代码,left(inv_name,12) 医保名称,'0' 部门,' ' 科室,
convert(varchar(8),getdate(),112) 日期,'后勤材料' as 备注, '0' as 状态
from mate_inv_dict a
where is_charge = '1' and isnull(edate,'')=''--状态 = '1'
and isnull(retail_price,0)<>0
and (add_date= convert(varchar(8),getdate(),112) or update_date= convert(varchar(8),getdate(),112))
and inv_code not in (select 代码 from [192.168.1.18,1433].fghisdb.dbo.代码_收费项目接口表)
if exists (select 1 from [192.168.1.18,1433].fghisdb.dbo.代码_收费项目接口表 A where A.类别 in ('13','47') and A.状态='0' and A.备注='后勤材料'and A.代码 not in (select inv_code from mate_inv_dict where is_charge='1' and isnull(edate,'')=''))
begin
update A set 备注='无此后勤材料',状态='1',日期=convert(varchar(8),getdate(),112)
From [192.168.1.18,1433].fghisdb.dbo.代码_收费项目接口表 A
where A.类别 in ('13','47') and
A.状态='0' and A.备注='后勤材料'and A.代码 not in
(select inv_code from mate_inv_dict where is_charge='1' and isnull(edate,'')='')-- fghishq.dbo.代码_后勤材料项目 where )--收费代码='1' and 状态='1')
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
------解决方案--------------------a)使用T-SQL语法:
SELECT * FROM LNK1..用户名.表名--注意用户名称,表名称要大写。
b)使用PLSQL语法:
select * from openquery(LNK1,'select&nbs