0

你能帮我吗,请修复以下 SQL 语句,我在第一行有错误。谢谢

DECLARE @T_SYS_FROM SMALLINT,VARCHAR(8);
    SET @T_SYS_FROM = 20200922,DATE;
    SELECT 
      T_SYS_FROM, 
      N_D_AHDJ,
      N_FUND_ID,
      N_AHDJ,
      T_SYS_USER,
      BUDAT
    FROM 
      dss.acn_ahdj_h
    where
      T_SYS_FROM=@ T_SYS_FROM
    ORDER by
      T_SYS_USER;
4

1 回答 1

2

DECLARE看起来像是从另一种 SQL 方言中获取语法,因为它不是有效的 Oracle PL/SQL 语法。

如果您使用的是 PL/SQL,那么类似(假设您的查询将返回恰好一行):

DECLARE 
  v_your_date DATE := DATE '2020-09-22';
  v_T_SYS_FROM dss.acn_ahdj_h.T_SYS_FROM%TYPE;
  v_N_D_AHDJ   dss.acn_ahdj_h.N_D_AHDJ%TYPE;
  v_N_FUND_ID  dss.acn_ahdj_h.N_FUND_ID%TYPE;
  v_N_AHDJ     dss.acn_ahdj_h.N_AHDJ%TYPE;
  v_T_SYS_USER dss.acn_ahdj_h.T_SYS_USER%TYPE;
  v_BUDAT      dss.acn_ahdj_h.BUDAT%TYPE;
BEGIN
  SELECT T_SYS_FROM, 
         N_D_AHDJ,
         N_FUND_ID,
         N_AHDJ,
         T_SYS_USER,
         BUDAT
  INTO   v_T_SYS_FROM, 
         v_N_D_AHDJ,
         v_N_FUND_ID,
         v_N_AHDJ,
         v_T_SYS_USER,
         v_BUDAT
  FROM   dss.acn_ahdj_h
  WHERE  T_SYS_FROM = v_your_date
  ORDER BY T_SYS_USER;
END;
/

如果你想要一个 SQL 查询,那么:

SELECT T_SYS_FROM, 
       N_D_AHDJ,
       N_FUND_ID,
       N_AHDJ,
       T_SYS_USER,
       BUDAT
FROM   dss.acn_ahdj_h
WHERE  T_SYS_FROM = DATE '2020-09-22'
ORDER BY T_SYS_USER;
于 2020-10-02T09:27:16.960 回答