【问题标题】:Query to get number of % sign = length of string in the next row in Oracle 10g查询以获取 Oracle 10g 中下一行中的 % 符号数 = 字符串长度
【发布时间】:2015-04-25 17:35:06
【问题描述】:

Oracle10G 中是否有任何 SQL 查询可以提供以下示例中所需的输出。 查询应该首先打印名称,然后在第二行打印与字符串长度相等的“%”。

你能帮忙吗?

下面是表格列的示例

JIM
JOHN
MICHAEL

输出应该如下所示:

JIM
%%%
JOHN
%%%%
MICHAEL
%%%%%%%

【问题讨论】:

    标签: sql oracle oracle10g


    【解决方案1】:

    这通常被认为是表示逻辑的问题,而不是数据库逻辑的问题。但是,一种选择是使用union all,然后使用lengthrpad 来获得正确数量的% 符号。您还需要建立一个行号以将订单保持在一起。

    这是一种方法:

    select name
    from (
      select name, rownum rn
      from yourtable
      union all
      select rpad('%', length(name), '%') name, rownum + 1 rn
      from yourtable ) t
    order by rn, name
    

    【讨论】:

      【解决方案2】:

      您可以查看此链接 http://www.club-oracle.com/articles/oracle-pivoting-row-to-column-conversion-techniques-sql-166/

      讨论了很多选项,这会有所帮助

      【讨论】:

        猜你喜欢
        • 2022-01-13
        • 1970-01-01
        • 2017-03-20
        • 2014-06-09
        • 2020-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多