保持Ref Cursor记录原样?

时间:2013-09-12 07:08:59

标签: sql oracle

请查看以下方案。

视图al_name_vw

No    Name

1     Murugan
2     xxxxx
3     yyyyy
4     bbbbb
5     aaaaa

我已经从下面的ref光标中获取数据。

open p_ref_name for
 select  anv.no,
         anv.Name
 from    al_name_vw anv 
order by anv.name;

所以我得到了结果

No    Name

5     aaaaa
4     bbbbb
1     Murugan
2     xxxxx
3     yyyyy

现在我需要修改逻辑来检索下面的记录。

No    Name

5     aaaaa
4     bbbbb
2     xxxxx
3     yyyyy
1     Murugan

3 个答案:

答案 0 :(得分:0)

select anv.no,
       anv.Name
  from al_name_vw anv 
 order by case when substr(anv.Name,1,1) = lower(substr(anv.Name,1,1)) --ensures names starting
                    then 1                                             --with lowercase come first
                    else 2
                end,
          anv.Name;

答案 1 :(得分:0)

试试这个,

WITH
     T AS
     ( SELECT 1 NO, 'Murugan' NAME FROM dual
     UNION
     SELECT 2, 'xxxxx' FROM DUAL
     UNION
     SELECT 3, 'yyyyy' FROM DUAL
     UNION
     SELECT 4, 'bbbbb' FROM dual
     UNION
     SELECT 5, 'aaaaa' FROM DUAL
     )
SELECT *
FROM t
ORDER BY
     TRANSLATE (NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');

您的查询,

OPEN p_ref_name FOR
 SELECT  anv.NO,
         anv.NAME
 FROM    al_name_vw anv 
ORDER BY 
     TRANSLATE (NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');

答案 2 :(得分:0)

使用你的结果集我猜你需要先重复相同的字符,然后不重复。使用以下查询。如果不是您想要的,请在问题背后用逻辑更新您的问题。

 select  anv.no,
     anv.Name
  from  (select  no,
     Name, case when regexp_like(Name,'^(.)\1+$') then 1 else 2 end rn
  from    al_name_vw ) anv
  order by rn