ask cursor postgresql

Database dan Structured Query Language

ask cursor postgresql

Postby batozai » 19 Aug 2011, 11:05

halo para suhu......nubie mau tanya nih, apakah cursor di postgresql bisa diupdate isinya....?

thanks
i believe bill gates doesn't make his success by imitating what is exist
batozai
Junior Member
 
Posts: 46
Joined: 08 Jun 2010, 22:57

RE: ask cursor postgresql

Postby D.E » 19 Aug 2011, 11:52

Cursor bukannya sebatas pointer* aja ya?
:idea: Dude, if you don't understand the basics and just want to get someone else write the code for you, it means you really shouldn't study computer science. Find different field!
User avatar
D.E
Senior Member
 
Posts: 638
Joined: 04 May 2010, 18:12

RE: ask cursor postgresql

Postby batozai » 19 Aug 2011, 16:19

D.E wrote:Cursor bukannya sebatas pointer* aja ya?


ane juga ga tau boss.....baru nih di postgresql

berhubung cursor kayake ga memberi solusi,
sekarang ane buat function baru

Code: Select all
  1. create or replace function func_test()

  2. returns table(

  3.   nama VARCHAR)

  4. as

  5. $$

  6. DECLARE

  7.   lnama varchar;

  8.   rec record;

  9. begin

  10.    create TEMPORARY table tmp_nama(

  11.      nama VARCHAR

  12.      );

  13.    insert into tmp_nama values('AGUS COMANK');

  14.    insert into tmp_nama values('ADI');

  15.    insert into tmp_nama values('EGA');

  16.    insert into tmp_nama values('EVA');

  17.  

  18.   for rec in

  19.      select * from tmp_nama

  20.   loop

  21.     nama = rec.nama;

  22.     return next;

  23.   end loop;  

  24.    

  25.    

  26.    return ;

  27. end

  28. $$ language 'plpgsql';



kemudian tak panggil itu function : select * from func_test()

malah error......

Code: Select all
  1. ERROR:  relation "tmp_nama" already exists

  2. CONTEXT:  SQL statement "create TEMPORARY table tmp_nama(

  3.      nama VARCHAR

  4.      )"

  5. PL/pgSQL function "func_test" line 5 at SQL statement



apa ya masalahnya.....? disini harus memakai temporary table, untuk ngolah data...udah dari pagi utak atik ga ketemu - ketemu solusianya...... pls help me para suhu......
i believe bill gates doesn't make his success by imitating what is exist
batozai
Junior Member
 
Posts: 46
Joined: 08 Jun 2010, 22:57

RE: ask cursor postgresql

Postby Manz » 19 Aug 2011, 16:26

@batozai

gimana kalo ditambahin seperti ini

1. sebelum create table:

Code: Select all
  1. drop temporary table if exists tmp_nama;

  2. ...

  3. baru dibuat create temporary table



2. atau seperti ini :

Code: Select all
  1. create temporary table if not exists tmp_nama ( DDL )



moga mbantu ... gak ada postgrenya :biggrin:
-= Man'z =- yah begitulah mereka memanggilku...

Catatan koe : -=| Manz |=- it's me :wink:
User avatar
Manz
Member
 
Posts: 160
Joined: 06 May 2010, 08:09

RE: ask cursor postgresql

Postby elva_ivana » 19 Aug 2011, 16:29

kalau dilihat dari pesan error nya menandakan bahwa table yang anda create sudah ada ..
itu dapat dilihat dari error pada baris ke-5
saran : di drop dulu table tsb sebelum create, mudah2 an saja bisa membantu....

waduh ... keduluan sama mastah Manz ... :furious:
[img]http://orido.files.wordpress.com/2009/06/bismillah.jpg?w=300&h=100#78;h=100#78;h=100#78;h=100[/img]
User avatar
elva_ivana
Member
 
Posts: 95
Joined: 06 May 2010, 08:25

RE: ask cursor postgresql

Postby batozai » 19 Aug 2011, 17:12

thanks para suhu....udah bisa....di drop dulu
i believe bill gates doesn't make his success by imitating what is exist
batozai
Junior Member
 
Posts: 46
Joined: 08 Jun 2010, 22:57


Who is online

Users browsing this forum: No registered users and 1 guest

cron