AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-889053

Christian Bongiorno's questions

Martin Hope
Christian Bongiorno
Asked: 2025-03-29 09:46:55 +0800 CST

为什么在此脚本中使用空分隔符时 printf 会以 1 退出?

  • 5

我有这个脚本,它似乎printf '%s\0%s\0'以代码 1 退出,我不明白为什么。

我甚至强迫它使用 bash 版本 5.2 - 结果相同。

以下是示例脚本及其输出

#!/usr/bin/env bash
echo $BASH_VERSION
set -x
set -Eeuo pipefail

function prompt_creds {
  local username password
  read -rp "username " username
  read -rsp "password " password 
  printf '%s\0%s\0' "${username}" "${password}"
}

function main() {
  IFS=$'\0' read -r username password < <(prompt_creds )
  echo "name name is ${username}" "my password is ${password}"
}

main

使用和输出

./sample.sh 
3.2.57(1)-release
+ set -Eeuo pipefail
+ main
+ IFS=
+ read -r username password
++ prompt_creds
++ local username password
++ read -rp 'username ' username
username user
++ read -rsp 'password ' password
password ++ printf '%s\0%s\0' user pass
bash-5.2$ echo $?
1

我甚至尝试在 CLI 上简单运行它,并且它可以工作:

bash-5.2$ IFS=$'\0' read -r u p < <(printf '%s\0%s\0' user pass)
bash-5.2$ echo $u $p
userpass
bash
  • 2 个回答
  • 79 Views
Martin Hope
Christian Bongiorno
Asked: 2024-11-23 06:01:51 +0800 CST

在 Oracle 中:如何仅获取总和占总数的 x % 以上的记录

  • 7

我有这些数据:

select * from (
    select 'A' as JOB, 15 as errors from dual union all
    select 'B' as JOB, 17 as errors from dual union all
    select 'C' as JOB, 29 as errors from dual union all
    select 'D' as JOB, 27 as errors from dual union all
    select 'E' as JOB, 35 as errors from dual union all
    select 'F' as JOB, 32 as errors from dual union all
    select 'G' as JOB, 75 as errors from dual union all
    select 'H' as JOB, 31 as errors from dual union all
    select 'I' as JOB, 12 as errors from dual union all
    select 'J' as JOB, 10 as errors from dual
)

用文字来说,我需要:The jobs constituting the (top) 60% of errors

因此,在这种情况下,那将是(113):

select sum(errors) * .4 as cut_off from ...

最终结果将是这样的,因为它们的总和 < 113:

工作 错误
格 75
埃 三十五

我基本上需要一个过滤器来保持某种运行总和,然后一旦达到该值就丢弃所有内容。

我有这个查询,它不太有效,我不希望使用该with语句

with data as (
    select 'A' as JOB, 15 as errors from dual union all
        select 'B' as JOB, 17 as errors from dual union all
        select 'C' as JOB, 29 as errors from dual union all
        select 'D' as JOB, 27 as errors from dual union all
        select 'E' as JOB, 35 as errors from dual union all
        select 'F' as JOB, 32 as errors from dual union all
        select 'G' as JOB, 75 as errors from dual union all
        select 'H' as JOB, 31 as errors from dual union all
        select 'I' as JOB, 12 as errors from dual union all
        select 'J' as JOB, 10 as errors from dual
)
select k.*
from (
    select t.*,
           errors + LAG(errors, 1, 0) OVER (order by errors desc ) previous
    from data t
) k where previous >= (select sum(errors) *.4 from data) order by errors desc

我已经尝试过窗口总和:

select k.*
from (
    select t.*,
           SUM(errors) OVER (
               partition by JOB
               order by errors desc
               RANGE BETWEEN UNBOUNDED PRECEDING
                AND CURRENT ROW
          ) as limit
    from (
        select 'A' as JOB, 15 as errors from dual union all
        select 'B' as JOB, 17 as errors from dual union all
        select 'C' as JOB, 29 as errors from dual union all
        select 'D' as JOB, 27 as errors from dual union all
        select 'E' as JOB, 35 as errors from dual union all
        select 'F' as JOB, 32 as errors from dual union all
        select 'G' as JOB, 75 as errors from dual union all
        select 'H' as JOB, 31 as errors from dual union all
        select 'I' as JOB, 12 as errors from dual union all
        select 'J' as JOB, 10 as errors from dual
    ) t
) k order by errors desc
sql
  • 2 个回答
  • 26 Views
Martin Hope
Christian Bongiorno
Asked: 2024-11-19 02:29:34 +0800 CST

在 Oracle 中:如何按列值按组/群集排序

  • 6

这是我的数据样本

select * from (
    select 'A' as POD, 164 as result from dual union all
    select 'A' as POD, 3 as result from dual union all
    select 'A' as POD, 2 as result from dual union all
    select 'B' as POD, 409 as result from dual union all
    select 'B' as POD, 128 as result from dual union all
    select 'B' as POD, 5 as result from dual union all
    select 'C' as POD, 12391 as result from dual union all
    select 'C' as POD, 624 as result from dual union all
    select 'C' as POD, 405 as result from dual union all
    select 'C' as POD, 26 as result from dual union all
    select 'C' as POD, 3 as result from dual union all
    select 'C' as POD, 2 as result from dual
)

荚 结果
一个 164
一个 3
一个 2
乙 409
乙 128
乙 5
碳 12391
碳 624
碳 405
碳 二十六

我想要的是按照首次计数最高的组对它们进行排序:

荚 结果
碳 12391
碳 624
碳 405
碳 二十六
乙 409
乙 128
乙 5
一个 164
一个 3
一个 2

我甚至不知道如何用 SQL 来表达这个

Cresult在第一行中具有最高值,然后B具有第二高值A

sql
  • 2 个回答
  • 52 Views
Martin Hope
Christian Bongiorno
Asked: 2024-11-05 03:49:39 +0800 CST

在 jq 中,如何将对象数组合并为具有值数组的 1 个对象

  • 5

假设我有这个 json:

[
  {
    "first": 12355,
    "second": "abc"
  },
  {
    "first": 89010,
    "second": "def"
  },
  {
    "first": 23423,
    "second": "hij"
  },
  {
    "first": 23456,
    "second": "klm"
  },
  {
    "first": 11111,
    "second": "nop"
  }
]

我希望(一种通用形式)将它们合并为 1 个对象,其中每个键的值合并到相应值的数组中:

{
    "first" : [12355,89010,23423,23456,11111],
    "second" : ["abc","def","hij","klm","nop"]
}

我正在尝试这个,但它根本没有产生任何输出。

reduce .[] as $final (
    {};
    ((. | keys) as $k |
        map(
            ( (.[$k] // []) += ($final[$k] // []))
        )
    )
)
json
  • 2 个回答
  • 36 Views
Martin Hope
Christian Bongiorno
Asked: 2024-10-29 06:12:47 +0800 CST

如何在子 shell 失败时退出 shell 脚本并使用读取[重复]

  • 5
此问题这里已有答案:
如何在 Bash 中将变量设置为命令的输出? (16 个答案)
如何捕获“here-string”命令的失败? (4 个答案)
17 小时前关闭。

关注此帖子

我有这个 bash 脚本,我期望它在点击时完全终止false,但它却没有。我意识到我做的事情与链接的帖子略有不同。

#!/usr/bin/env bash
set -Eeuo pipefail

function thing() {
  false
  echo "thing1|thing2|thing3"
}
IFS='|' read -r one two three <<< "$(thing )"
echo "${one} ${two} ${three}"
echo "done"

输出:

thing1 thing2 thing3
done

理想情况下,我想在 zsh 中执行此操作,但我也遇到了我不想要的行为:


#!/usr/bin/env zsh
set -Eeuo pipefail

function thing() {
  false
  echo "thing1|thing2|thing3"
}
IFS='|' read -r one two three <<< "$(thing )"
echo "${one} ${two} ${three}"
echo "done"

输出:

  
done

如何实现这个功能?

bash
  • 2 个回答
  • 57 Views
Martin Hope
Christian Bongiorno
Asked: 2024-07-24 01:49:54 +0800 CST

如何在 Oracle 中创建具有 lambda 参数的函数?

  • 6

我似乎没有找到有关此的任何文档(也许我不知道 Oracle 对此的解释),但我想创建一个接受函数的函数:比如,让它传递给我一个排序函数。

当我看到这样的代码时:

LAG(FOO) OVER (PARTITION BY XXX ORDER BY YYY) AS thing

我感觉这正是这里发生的事情 ^^ 并且OVER子句是 lambda。

可以做到吗?我这样想对吗?如果有可行的示例就更好了。

oracle
  • 1 个回答
  • 36 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve