我有一个表存储员工姓名和工作年限。这些列是:
employeeID int NOT NULL,
year int NOT NULL
Run Code Online (Sandbox Code Playgroud)
主键是复合的:employeeID 和year。我需要选择表中存在 2012 年该员工 ID 的所有记录,但不选择 2011 年。换句话说,我需要一个在 2012 年工作但不在 2011 年工作的员工列表。我不知道为什么我不能这样做!如果您理解该问题,请跳过下面的 Java 代码。
如果我用 Java 解析员工表,它将是:
// This is what is returned at the end
List theQueryResults = new List();
// This would be all employees and the years they worked, assume it's filled.
Table employees = new Table (int employeeID, int year);
for (int i = 0; i < employees.count(); i++) {
boolean addToQuery = false;
for (int j …
Run Code Online (Sandbox Code Playgroud) 我不确定如果我一直没有看到这个编程语言的重要部分我是否错了.
简而言之,我的代码包含一个名为"buckets"的双精度数组.我的代码需要逐个索引地解析这个数组,检查它的值,并在一个名为"finalVals"的新数组中存储最后5个值.存储桶数组将包含大约100个值,其中大多数为零且不需要.5个连续零的序列将意味着我需要的数据的结束.所以我需要在桶中返回最后5个值,其中值都是非零值.它存储在名为"nonZeros"的数组中.
lastVal = new double[5]; // A global variable already declared but not set
double nonZeros[] = new double[5]; // A local variable
int numberOfZeros = 0;
for (int i = 0; i < buckets.length; i++) {
double val = buckets[i];
if (val == 0) {
System.out.println("Encountered a zero.");
numberOfZeros++;
lastVal[0] = lastVal[1];
lastVal[1] = lastVal[2];
lastVal[2] = lastVal[3];
lastVal[3] = lastVal[4];
lastVal[4] = val;
}
else if (val != 0) {
System.out.println("Did not encounter a zero.");
numberOfZeros = …
Run Code Online (Sandbox Code Playgroud) 使用 PL/SQL,我希望从 select 语句中以编程方式生成 CSV 字符串/varchar 对象。所以 select 语句的输出通常是 1-n 条记录(我只需要一列)。但关键是,我不能使用循环或任何迭代过程,而且必须在不使用外部库的情况下完成。
我可以自由地将数据转换为表格或不同的数据类型,并在需要时使用更多内存。但我不能明确使用循环。
我想我正在寻找一种方法来做这样的事情:
declare
my_csv varchar2(4000);
begin
select implode(my_column,',') into my_csv
from my_table
where some_column = 'some value';
dbms_output.put_line('I got my list: ' || my_csv);
end;
Run Code Online (Sandbox Code Playgroud)
本质上,内爆理论上会像 PHP 内爆函数一样工作,而“,”逗号是我的分隔符。我可以自己定义内爆函数,但同样,我不能明确使用循环。
有任何想法吗?