返回可在SQL(oracle)中使用的数据类型的函数 [英] function that return data type that can be used in SQL(oracle)

查看:86
本文介绍了返回可在SQL(oracle)中使用的数据类型的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我使用的是oracle sql:

For example I was using oracle sql:

SELECT rpad(salary, 10 , '*')
from employees;

在"10"部分,希望我可以使用一个函数直接返回数据类型的字节. 我尝试过

At the "10" part, I wish I can use a function to directly return the byte of the data type. I tried

SELECT rpad(salary, salary, '*')
from employees;

结果令人震惊.

有没有办法做到这一点,或者我必须在plsql中创建一个函数?

is there any way to do it, or I have to create a function in plsql?

推荐答案

您可以使用以下方法填充整个表格中列的最大数据长度:

You can fill to max length of data in the column in the whole table using the below:

  select rpad( salary,  
      max(length(salary)) over (partition by (select null from dual)), 
       '*') 
   from  employees

或者使用user_tab_columns表中的data_length达到最大可能的大小

Or to full possible size using data_length in user_tab_columns table

select rpad( salary,  
     (select data_length from user_tab_columns 
        where table_name = 'EMPLOYEES' and 
        column_name = 'SALARY' ), 
     '*') from  employees

这篇关于返回可在SQL(oracle)中使用的数据类型的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆