简体   繁体   English

如何在 oracle 11g 中格式化 select 查询的列长度?

[英]How to format column length on select query in oracle 11g?

I have problem in formatting column length using select query in oracle 11g.我在使用 oracle 11g 中的 select 查询格式化列长度时遇到问题。 This is my table structure:这是我的表结构: 在此处输入图像描述

I'm trying to format judul_buku length into 50, but it seems didn't work when im using RPAD syntax.我正在尝试将 judul_buku 长度格式化为 50,但是当我使用 RPAD 语法时它似乎不起作用。 This is my query:这是我的查询:

SELECT rpad(b.judul_buku, 50) as "Buku"
from buku b;

This is the output (came out wrong because the length is more than 50).这是output(因为长度超过50而出现错误)。 在此处输入图像描述

I have tried to search how to format column length from select query but i can't find the right keyword to search it so i can't find any syntax to change column length.我试图从 select 查询中搜索如何格式化列长度,但我找不到正确的关键字来搜索它,所以我找不到任何语法来更改列长度。

I'm using oracle 11g and i can't change the version since my lecturer told me to use oracle 11g and she only teach RPAD and LPAD to reduce column length (which didn't work for me and my friend).我正在使用 oracle 11g,我无法更改版本,因为我的讲师告诉我使用 oracle 11g,她只教 RPAD 和 LPAD 以减少列长度(这对我和我的朋友不起作用)。

Is there any other way to reduce column length instead RPAD LPAD?有没有其他方法可以减少列长度而不是 RPAD LPAD?

How about casting to char(50) ?投射到char(50)怎么样?

select cast(b.judul_buku as char(50)) as "Buku"
from buku b;

This sets the type and pads the value with 50 spaces if the value is shorter.如果值较短,这将设置类型并用 50 个空格填充值。 That said, this type of formatting is usually done in the application.也就是说,这种类型的格式化通常在应用程序中完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM