小编Mik*_*rez的帖子

从游标PostgreSQL中获取行

我有光标代码:

BEGIN;
DECLARE cliente_cursor 
CURSOR FOR SELECT * FROM cliente;
Run Code Online (Sandbox Code Playgroud)

我想阅读表'cliente'中的所有内容:

表客户

使用游标.我有适用于SQL Server的代码:

DECLARE cliente_cursor CURSOR
      FOR SELECT * FROM cliente
OPEN cliente_cursor
FETCH NEXT FROM cliente_cursor;
While @@FETCH_STATUS=0
BEGIN
     FETCH NEXT FROM cliente_cursor;
End
CLOSE cliente_cursor
DEALLOCATE cliente_cursor
Run Code Online (Sandbox Code Playgroud)

我希望有一个适用于PostgreSQL的代码.

我一直在寻找解决方案,看到人们通常建议使用功能.我想知道这个PostgreSQL DBMS中是否有任何方法可以创建与SQL Server中的代码类似的东西.

我写了这段代码:

CREATE OR REPLACE FUNCTION MyFunction()
RETURNS setof cliente AS $$
DECLARE 
cursor_cliente CURSOR FOR SELECT * FROM cliente;
rec cliente%ROWTYPE;
 BEGIN
 OPEN cursor_cliente;
loop
--fetch the table row inside the loop
FETCH cursor_cliente INTO rec;
-- …
Run Code Online (Sandbox Code Playgroud)

postgresql cursor

3
推荐指数
1
解决办法
2万
查看次数

使用Java中的方法返回一个数组

我有个疑问.我正在开发以下代码,它将是您手动引入的数字的多重表.我不能得到的是打印表格.我不知道发生了什么,因为据我所知,所有的代码都是正确的.

public class Tabla 
{

public static void main (String[] args) 
{        
    int n=4;       

    Tabla table = new Tabla ();
    int dato [];
    dato=table.producto(n);        

    for (int j=1;j<=10;j++)
    {System.out.println(dato[j]);}

}



public int [] producto(int num) 
{ 
    int a[]={'0'};

    for (int i=1;i<=10;i++)
    {a[i]=num*i;}

    return a;


}    

}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗??

提前致谢!

**我将代码更改为:

public class Tabla 
{

    public static void main (String[] args) 
    {        
        int n=4;       
        int j;

        Tabla table = new Tabla ();
        int dato[]=new int [10];
        dato=table.producto(n);        

        for (j=0;j<10;j++)
        {System.out.println(dato[j]);
        }

    }



    public …
Run Code Online (Sandbox Code Playgroud)

java arrays methods

-1
推荐指数
1
解决办法
108
查看次数

标签 统计

arrays ×1

cursor ×1

java ×1

methods ×1

postgresql ×1