DECLARE @count INT
SELECT @count = COUNT(*) FROM tests
SELECT @count AS totalCounts,* FROM tests这个是sqlserver语法。在oracle中,怎么写?

解决方案 »

  1.   

    /*
    DECLARE @count INT
    SELECT @count = COUNT(*) FROM tests
    SELECT @count AS totalCounts,* FROM tests
    */
    declare
    cnt int := 0;
    begin
      select count(1) into cnt from tests;
      select cnt as totalcounts,字段列表(请一一写出来 ORACLE不支持单表使用字段+*的用法) from tests;
    end;
      

  2.   


    在行 1 上开始执行命令时出错:
    declare
    cnt int := 0;
    begin
      select count(*) into cnt from users;
      select cnt as totalcounts,USERID,
      USERNAME,
      USERSEX,
      USERAGE,
      USERPASSWORD,
      USERCREATETIME,
      USERTYPEID from users;
    end;
    错误报告:
    ORA-06550: 第 5 行, 第 3 列: 
    PLS-00428: 在此 SELECT 语句中缺少 INTO 子句
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
      

  3.   

    ……这个怎么说呢, 最后一句需要后续处理,在ORACLE里不支持无返回值的SELECT查询。
    比如说改成:
    create table t_test as
    select cnt as totalcounts,USERID,
      USERNAME,
      USERSEX,
      USERAGE,
      USERPASSWORD,
      USERCREATETIME,
      USERTYPEID from users;
      

  4.   


    SQLServer 执行SELECT @count AS totalCounts,* FROM tests直接就返回结果集Oracle必须声明一个动态游标返回结果集
    declare
    cnt number(20,0) := 0;
    cur sys_refcursor;
    begin
      select count(*) into cnt from users;
      
      open cur for
      select cnt as totalcounts,USERID,
      USERNAME,
      USERSEX,
      USERAGE,
      USERPASSWORD,
      USERCREATETIME,
      USERTYPEID from users;
    end;