先看原mysql语句:
SELECT
xs.` F_zy ` AS ` F_zy `,
xs.` F_yx ` AS ` F_yx `,
xs.` F_bj ` AS ` F_bj `,
xs.` F_xsm ` AS ` F_xsm `,
xs.` F_xb ` AS ` F_xb `,
xs.` F_xslx ` AS ` F_xslx `,
rz.` F_xq ` AS ` F_xq `,
rz.` F_ld ` AS ` F_ld `,
rz.` F_lc ` AS ` F_lc `,
rz.` F_fj ` AS ` F_fj `,
rz.` F_fjxb ` AS ` F_fjxb `,
gy.` F_jc ` AS ` F_jc `,
gy.` F_fjbz ` AS ` F_fjbz `
FROM
w_xsxxb AS xs left join w_plrzsq AS rz ON
convert( xs.` F_xsm ` using utf8mb4 ) = convert( rz.` F_xm ` using utf8mb4 )
left join w_gyxx AS gy ON
convert( rz.` F_cwh ` using utf8mb4 ) = convert( gy.` F_cwbh ` using utf8mb4 )
ORDER BY
rz.` F_fj`
这个是navicat里视图的原语句,字段啥的不用在意,业务相关的,主要就是连两张表进行查询,关联条件是两个字段在转为utf8后比较
看看报错:
第一个: ORA-00911: invalid character,无效字符
解决:因为navicat的自身设置,视图sql的字段会被加上 ` 这个字符,全部去除,解决。
第二个:RA-00907: missing right parenthesis,缺少右括号
这个报错的原因比较打哑谜,认真排查了,基本确定不是缺少括号的问题,后经一番查阅,找到实际原因
解决:1.oracle数据库要求给表取别名是不能加as关键字(字段别名无所谓),将其全部去除
2.就是oracle的字段类型转换函数使用,一是使用方式不同,二是转换的字符集和mysql不同,看最终sql:
SELECT
xs.F_zy AS F_zy,
xs.F_yx AS F_yx,
xs.F_bj AS F_bj,
xs.F_xsm AS F_xsm,
xs.F_xb AS F_xb,
xs.F_xslx AS F_xslx,
rz.F_xq AS F_xq,
rz.F_ld AS F_ld,
rz.F_lc AS F_lc,
rz.F_fj AS F_fj,
rz.F_fjxb AS F_fjx,
gy.F_jc AS F_jc,
gy.F_fjbz AS F_fjbz
FROM
w_xsxxb xs
LEFT JOIN w_plrzsq rz ON CONVERT( xs.F_xsm,'AL32UTF8' ) = CONVERT( rz.F_xm,'AL32UTF8' )
LEFT JOIN w_gyxx gy ON CONVERT( rz.F_cwh,'AL32UTF8' ) = CONVERT( gy.F_cwbh,'AL32UTF8' )
ORDER BY
rz.F_fj
字符集:AL32UTF8(其中AL代表ALL,指适用于所有语言)
看on后面跟的条件,对比一下即可。
继续更新
ORA-12704: character set mismatch 字符集错误
SELECT
w_bxsq.F_sqrzhm,
(
CASE
WHEN w_bxsq.F_cljg = '' THEN
'处理中' ELSE w_bxsq.F_cljg
END
) AS F_clzt7
FROM
w_bxsq
在case when里then作为when条件成立后的结果,不能直接用中文字符串,改成如下:
SELECT
w_bxsq.F_sqrzhm,
(
CASE
WHEN w_bxsq.F_cljg = '' THEN
cast( '处理中' AS NVARCHAR2 ( 32 ) ) ELSE w_bxsq.F_cljg
END
) AS F_clzt7
FROM
w_bxsq
用cast()函数转换下数据类型解决。
再更
ORA-00920: invalid relational operator 无效的关系运算符
不放sql了,原因是Oracle中没有isnul()函数,用字段名 is null 替换解决。