Oracle 'printf' эквивалент

Вы пробовали использовать другой SSH-клиент? Некоторые клиенты SSH имеют специальные встроенные сопоставления клавиш для разных удаленных процессов. Я столкнулся с этим много с emacs.

Какой клиент вы используете? Я бы рекомендовал попробовать Putty и SecureCRT сравнить их поведение.

13
задан Steven 17 June 2009 в 04:14
поделиться

3 ответа

Нет встроенных функций Oracle, которые применяют строку форматирования таким образом. Хотя было бы легко написать собственную функцию для этого конкретного примера, написание реализации printf на основе PL / SQL было бы сложной задачей.

Если вам это часто нужно, возможно, вы могли бы написать функцию Oracle, которая обертывает вызов Java для более богатой среды обработки строк.

7
ответ дан 1 December 2019 в 19:50
поделиться

You can resolve it in the select.

SELECT mix_type || '(' ||  mix_num || ')' as description,
FROM acid_batch
WHERE mix_num < 10

you should also take a look at the functions

to_char

to_date

to_number

as they give your a finer granularity on how you want the things represented.

1
ответ дан 1 December 2019 в 19:50
поделиться

Just another idea for you: I've found REPLACE to be useful for this kind of thing, especially when the template is complex:

SELECT REPLACE(REPLACE(
        '%mix_type% (%mix_num%)' /*template*/
       ,'%mix_type%', mix_type)
       ,'%mix_num%' , mix_num ) as description,
FROM   acid_batch
WHERE  mix_num < 10

The only downside is you need to add as many REPLACE('s as there are variables to replace - but at least you only need to have one per variable, regardless of how many times it appears in the template.

(NOTE: There is no particular significance to using "%" as a delimiter, it's just a personal convention of mine - you might choose a different pattern, e.g. or [mix_type])

For this particular instance it looks like overkill, but in some cases it can make things much easier, e.g.:

template := 'bla bla %a% %b% %a%';
output := REPLACE(REPLACE(template
    ,'%a%', some_complex_expression)
    ,'%b%', b);

Compare the above with:

output := 'bla bla ' || some_complex_expression || ' ' || b || ' ' || some_complex_expression;
3
ответ дан 1 December 2019 в 19:50
поделиться
Другие вопросы по тегам:

Похожие вопросы: