我已经通过liquibase将oracle数据库迁移到Microsoft SQL Server,但是仍然有些SQL语句不起作用。这个在oracle中看起来像这样:
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed
examples.
##
# Default server configuration
upstream app {
# Path to Puma SOCK file, as defined previously
server unix:/tmp/gms-puma.sock fail_timeout=0;
}
server {
listen 8001;
server_name localhost;
root /home/deploy_user/gms/current/public;
try_files $uri/index.html $uri @app;
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_pass http://app;
}
location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
将其迁移到Microsoft SQL Server后,如下所示:
CREATE OR REPLACE VIEW "BP_RESULTS_VIEW" (
BP_ID,
RES_NAME,
RES_LONG_NAME,
MEDIAN,
LOW_HINGE,
HIGH_HINGE,
H_SPREAD,
INNER_FENCE_LOW,
INNER_FENCE_HIGH,
OUTER_FENCE_LOW,
OUTER_FENCE_HIGH,
LOW_NOTCH,
HIGH_NOTCH,
LOW_ADJACENT_VALUE,
HIGH_ADJACENT_VALUE)
AS
SELECT
r.BP_ID,
rv.RES_NAME,
rv.RES_LONG_NAME,
r.MEDIAN,
r.LOW_HINGE,
r.HIGH_HINGE,
r.H_SPREAD,
r.INNER_FENCE_LOW,
r.INNER_FENCE_HIGH,
r.OUTER_FENCE_LOW,
r.OUTER_FENCE_HIGH,
r.LOW_NOTCH,
r.HIGH_NOTCH,
r.LOW_ADJACENT_VALUE,
r.HIGH_ADJACENT_VALUE
FROM
bp_results r,
results_view_display rv
WHERE
CAST (rv.value AS INT) = r.bp_id AND
rv.type = 'BOX';
但是当我要执行它时,总是会发生此错误:
CREATE OR REPLACE FORCE VIEW BP_RESULTS_VIEW (BP_ID, RES_NAME, RES_LONG_NAME, MEDIAN,
LOW_HINGE, HIGH_HINGE, H_SPREAD, INNER_FENCE_LOW, INNER_FENCE_HIGH,
OUTER_FENCE_LOW, OUTER_FENCE_HIGH, LOW_NOTCH, HIGH_NOTCH,
LOW_ADJACENT_VALUE, HIGH_ADJACENT_VALUE) AS SELECT
r.BP_ID,
rv.RES_NAME,
rv.RES_LONG_NAME,
r.MEDIAN,
r.LOW_HINGE,
r.HIGH_HINGE,
r.H_SPREAD,
r.INNER_FENCE_LOW,
r.INNER_FENCE_HIGH,
r.OUTER_FENCE_LOW,
r.OUTER_FENCE_HIGH,
r.LOW_NOTCH,
r.HIGH_NOTCH,
r.LOW_ADJACENT_VALUE,
r.HIGH_ADJACENT_VALUE
FROM
bp_results r,
results_view_display rv
WHERE
CAST (rv.value AS INT) = r.bp_id AND
rv.type = 'BOX'
GO
我不明白为什么,因为REPLACE语句也存在于SQL Server中。似乎也无法识别CAST命令。我正在使用Microsoft SQL Server Management Studio 17
答案 0 :(得分:2)
在SQL Server 2016 SP1和更高版本(包括Azure SQL数据库)中,使用CREATE OR ALTER VIEW
获得等效功能。在SQL Server的早期版本中,必须先删除视图,然后是CREATE VIEW
和GRANT
权限。
答案 1 :(得分:0)
SQL Server不支持CREATE OR REPLACE VIEW
。
相反,是第一次创建视图。然后只需使用ALTER VIEW
。那是最简单的方法。您还可以删除视图并重新创建它。