Jump to content

sql help


kamapisaachi

Recommended Posts

ee query lo pid value one value at a time etla pass cheyyali ? pid values are stored in another table called table b.

 

example

select * from table a

where pid = 2

inko loop iteration lo

select * from table b

where pid = 3

itla 100-200 times pid value marusthu query run cheyyali. output will be exported to multiple text files.

 

Link to comment
Share on other sites

6 minutes ago, kamapisaachi said:

ee query lo pid value one value at a time etla pass cheyyali ? pid values are stored in another table called table b.

 

example

select * from table a

where pid = 2

inko loop iteration lo

select * from table b

where pid = 3

itla 100-200 times pid value marusthu query run cheyyali. output will be exported to multiple text files.

 

Cursor

Link to comment
Share on other sites

code it in shell script.. 

step 1) Output pid values to be iterated into a text file... create multiple files accordingly if it requires nested looping.

step 2) Use for loop to loop through all pid values from the text files..  redirect the output for every run into flat file according to your requirement.

Link to comment
Share on other sites

7 hours ago, kamapisaachi said:

ee query lo pid value one value at a time etla pass cheyyali ? pid values are stored in another table called table b.

 

example

select * from table a

where pid = 2

inko loop iteration lo

select * from table b

where pid = 3

itla 100-200 times pid value marusthu query run cheyyali. output will be exported to multiple text files.

 


 

Ni daggara linux environment undha? Or python undha? SQL lo ante stored procs lo rayali. Atleast what database ee chepou.

Link to comment
Share on other sites

declare

cursor c_pid as 

select distinct pid from table b;

P_output_value varchar2(1000);

Begin

For x in c_pid 

loop 

select output_value

into p_output_value 

from table a where a.<pid_foriegn_key> = x.pid;

dbms_output.print_line(‘value of pid is: ‘ || p_output_value); 

End loop; 

end; 

 

Link to comment
Share on other sites

4 minutes ago, Googlie said:

declare

cursor c_pid as 

select distinct pid from table b;

P_output_value varchar2(1000);

Begin

For x in c_pid 

loop 

select output_value

into p_output_value 

from table a where a.<pid_foriegn_key> = x.pid;

dbms_output.print_line(‘value of pid is: ‘ || p_output_value); 

End loop; 

end; 

 

This is code for oracle database 

You can run in sql developer 

it prints the pid value in output window 

 

but if u need to write to a file then you can use a file function like fnd_file or a shell script etc 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...