How to take output of execute immediate 'select * from table' into a file ?
hi all,
below is my code .....
declare
var_column_name varchar2(2000);
main_string varchar2(12000);
var_table_name varchar2(30);
base_string varchar2(2000);
final_string varchar2(2000);
cursor c1 is
select
object_name
from user_objects
where object_type in ('TABLE','VIEW') and rownum < 2 ;
cursor c2 is
select
column_name
from user_tab_columns
where upper(table_name) = upper(var_table_name);
begin
--var_column_name := null;
-- main_string :=null;
-- table_name :=null ;
-- base_string :=null;
-- final_string := null;
open c1;
fetch c1 into var_table_name;
close c1;
for c2_var in c2
loop
main_string := c2_var.column_name||','||main_string;
end loop;
select rtrim(main_string,',') into final_string from dual;
dbms_output.put_line(final_string);
base_string := 'Select '||final_string ||' from '||var_table_name||'' ;
dbms_output.put_line(base_string);
spool tete.lst;
execute immediate base_string;
spool off;
end;
i want to take the output of the execute immediate in a file on unix server ....
please suggest
rgds
s
Were you looking for something like this?
SELECT
CASE WHEN Columns.Column_Id = 1 THEN 'SELECT ' || CHR(10) END
|| CHR(09) || Columns.Column_Name
|| CASE
WHEN Columns.Column_Id = Info.Total_Columns THEN
CHR(10) || 'FROM'
|| CHR(10) || CHR(09) || Columns.Table_Name || ';'
|| CHR(10)
ELSE ','
END Statement
FROM
User_Tab_Columns Columns,
SELECT
Table_Name,
MAX(Column_Id) Total_Columns
FROM
User_Tab_Columns
GROUP BY
Table_Name
) Info
WHERE
Columns.Table_Name = Info.Table_Name
ORDER BY
Columns.Table_Name,
Columns.Column_Id;
Similar Messages
-
How to take Purchase order Pending quantity value from Table. ?
Hai SAP Gurus,
Now Using ME2N, I am taking Pending Purchase Order Value against Plant wise & Material Type wise. Its takes lomg time to see this report.. Kindly guide me how to takes those value from table..?
ex: Material Type Plant 1
RM 1716294228
HIBE 63586533
ERSA 27143712
VERP 7551982745
Components 7375781142
Total Rs. 16734788360Hi
It is possible through ME2N plantwise pend PO report.
Put plant and WE101 in selection parameters -
Select * from table into table field-symbol
Hello,
I am trying to do a dynamic select into a dynamically defined internal table (field-symbol), but it doesn't work like I expected.
if I try this code :
data : p_tabname type string value 'PA9006',
dref type ref to data .
FIELD-symbols: <struc> TYPE ANY.
CREATE DATA dref TYPE table of (p_tabname).
ASSIGN dref->* TO <struc>.
SELECT * INTO TABLE <struc> FROM (p_tabname) .
I get the following error :
<struc> is not an internal table.
Is there any way I can make this work?
Points will be assigned for each usefull answer.Hi Dries
Just change your declaration of <struc> to as below it would work,
field-symbols : <struc> type standard table.
Reward points if useful.
~Ranganath -
Select from ODS into .CSV file
hi guru's !
I need to build an abap program that reads a number of fields from an ODS (table) and stores this result in a .CSV file.
I have never done this before so any documentation or examples would be greatly appreciated !
thanks alread !hi,
http://help.sap.com/saphelp_nw04/helpdata/en/c7/dc833b2ab3ae0ee10000000a11402f/frameset.htm
Regards,
Sourabh -
How to display result of execute immediate on sql prompt
I wish to create a dynamic select statement where i will give table name and where condition as input parameters at runtime. for this i created following procedure:
CREATE or replace PROCEDURE select_rows (
table_name IN VARCHAR2,
condition IN VARCHAR2 DEFAULT NULL)
AS
where_clause VARCHAR2(100) := ' WHERE ' || condition;
BEGIN
IF condition IS NULL THEN where_clause := NULL; END IF;
EXECUTE IMMEDIATE 'select * FROM ' || table_name || where_clause;
END;
my procedure is successfully created.
my problem is how to get select stmt output at screen (sql prompt)
or how to spool the output in a file.
plz. help me. I am learning oracle .
thanx in adv.
ManiYou could use refcursors. Example :
TEST@db102 > CREATE or replace PROCEDURE select_rows (
2 table_name IN VARCHAR2,
3 condition IN VARCHAR2 DEFAULT NULL,
4 cur1 out sys_refcursor)
5 AS
6 where_clause VARCHAR2(100) := ' WHERE ' || condition;
7 BEGIN
8 IF condition IS NULL THEN where_clause := NULL; END IF;
9 open cur1 for 'select * from '||table_name||where_clause;
10 END;
TEST@db102 > /
Procedure created.
TEST@db102 > var cur refcursor;
TEST@db102 > exec select_rows('emp','deptno=20',:cur);
PL/SQL procedure successfully completed.
TEST@db102 > print cur
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
TEST@db102 > -
How to achieve that "SELECT * FROM table WHERE age BETWEEN 18 AND 23 AND n"
How to achieve the SQL like that "SELECT * FROM table WHERE age BETWEEN 18 AND 23 AND name = 'Will' " with BDB C-API
The primary key in the primary database is 'age' ,and the secondary key in the secondary index is 'name' ,in a lot of examples ,there are all simple , but how to do that complex one.thx~but this means that the prepared statement is created
each time I call my method and so I'm not sure that
the optimizer will find it easy to cope with.You are right, the optimizer won't find that easy to deal with (presuming that is even relevant for your driver/database.) But most optimizers won't do anything with statements that change and that is what you are doing.
You could create several prepared statements which have a common number of bind variables. For example 10 statements with from 1 to 10 bind values. This will work if most of the queries use those. -
Using execute immediate creating a table from another
hi friend i wanted to create a table from a select statement in a pl sql procedure. i am using execute immediate but getting problems with it pls can anyone help me.
here is the query i am using
EXECUTE IMMEDIATE 'CREATE TABLE table_name AS (SELECT * FROM a_view WHERE column_name LIKE '%some_string%');
i need to know if this can be done and if yes how. pls help me its bit urgent too. the schema name is same and the privileges are available to create tables too.Your syntax is wrong.
If you would use a syntax higlighted editor, it would show.
Yout try to execute a string where another string is embedded. Please use two times single quote or use the 'q' function:
This one is correct:
EXECUTE IMMEDIATE 'CREATE TABLE table_name AS (SELECT * FROM a_view WHERE column_name LIKE ''%some_string%'')';
or this one:
EXECUTE IMMEDIATE q'|CREATE TABLE table_name AS (SELECT * FROM a_view WHERE column_name LIKE '%some_string%')|';
good luck -
Error while insert data using execute immediate in dynamic table in oracle
Error while insert data using execute immediate in dynamic table created in oracle 11g .
first the dynamic nested table (op_sample) was created using the executed immediate...
object is
CREATE OR REPLACE TYPE ASI.sub_mark AS OBJECT (
mark1 number,
mark2 number
t_sub_mark is a class of type sub_mark
CREATE OR REPLACE TYPE ASI.t_sub_mark is table of sub_mark;
create table sam1(id number,name varchar2(30));
nested table is created below:
begin
EXECUTE IMMEDIATE ' create table '||op_sample||'
(id number,name varchar2(30),subject_obj t_sub_mark) nested table subject_obj store as nest_tab return as value';
end;
now data from sam1 table and object (subject_obj) are inserted into the dynamic table
declare
subject_obj t_sub_mark;
begin
subject_obj:= t_sub_mark();
EXECUTE IMMEDIATE 'insert into op_sample (select id,name,subject_obj from sam1) ';
end;
and got the below error:
ORA-00904: "SUBJECT_OBJ": invalid identifier
ORA-06512: at line 7
then when we tried to insert the data into the dynam_table with the subject_marks object as null,we received the following error..
execute immediate 'insert into '||dynam_table ||'
(SELECT887684 wrote:
ORA-00904: "SUBJECT_OBJ": invalid identifier
ORA-06512: at line 7The problem is that your variable subject_obj is not in scope inside the dynamic SQL you are building. The SQL engine does not know your PL/SQL variable, so it tries to find a column named SUBJECT_OBJ in your SAM1 table.
If you need to use dynamic SQL for this, then you must bind the variable. Something like this:
EXECUTE IMMEDIATE 'insert into op_sample (select id,name,:bind_subject_obj from sam1) ' USING subject_obj;Alternatively you might figure out to use static SQL rather than dynamic SQL (if possible for your project.) In static SQL the PL/SQL engine binds the variables for you automatically. -
How to get the path when i select a directory or a file in a JTree
How to get the path when i select a directory or a file in a JTree
import java.lang.*;
import java.io.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.HeadlessException;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Iterator;
* @author Frederic FOURGEOT
* @version 1.0
public class JTreeFolder extends JPanel {
protected DefaultMutableTreeNode racine;
JTree tree;
protected JScrollPane scrollpane;
final static int MAX_LEVEL = 1; // niveau max de descente "direct" dans l'arborescence
* Sous-classe FSNode
* @author Frederic FOURGEOT
* @version 1.0
private class FSNode extends DefaultMutableTreeNode {
File file; // contient le fichier li� au noeud
* Constructeur non visible
private FSNode() {
super();
* Constructeur par initialisation
* @param userObject Object
FSNode(Object userObject) {
super(userObject);
* Constructeur par initialisation
* @param userObject Object
* @param newFile File
FSNode(Object userObject, File newFile) {
super(userObject);
file = newFile;
* Definit le fichier lie au noeud
* @param newFile File
public void setFile(File newFile) {
file = newFile;
* Renvoi le fichier lie au noeud
* @return File
public File getFile() {
return file;
public JTree getJTree(){
return tree ;
* Constructeur
* @throws HeadlessException
public JTreeFolder() throws HeadlessException {
File[] drive;
tree = new JTree();
// cr�ation du noeud sup�rieur
racine = new DefaultMutableTreeNode("Poste de travail");
// cr�ation d'un noeud pour chaque lecteur
drive = File.listRoots();
for (int i = 0 ; i < drive.length ; i++) {
FSNode node = new FSNode(drive, drive[i]);
addFolder(drive[i], node); // on descend dans l'arborescence du lecteur jusqu'� MAX_LEVEL
racine.add(node);
// Gestion d'evenement sur JTree (on �coute les evenements TreeExpansion)
tree.addTreeExpansionListener(new TreeExpansionListener() {
public void treeExpanded(TreeExpansionEvent e) {
// lorsqu'un noeud est ouvert
// on descend dans l'arborescence du noeud jusqu'� MAX_LEVEL
TreePath path = e.getPath();
FSNode node = (FSNode)path.getLastPathComponent();
addFolder(node);
((DefaultTreeModel)tree.getModel()).reload(node); // on recharche uniquement le noeud
public void treeCollapsed(TreeExpansionEvent e) {
// lorsqu'un noeud est referm�
//RIEN
// alimentation du JTree
DefaultTreeModel model = new DefaultTreeModel(racine);
tree.setModel(model);
setLayout(null);
// ajout du JTree au formulaire
tree.setBounds(0, 0, 240, 290);
scrollpane = new JScrollPane(tree);
add(scrollpane);
scrollpane.setBounds(0, 0, 240, 290);
* Recuperation des sous-elements d'un repertoire
* @param driveOrDir
* @param node
public void addFolder(File driveOrDir, DefaultMutableTreeNode node) {
setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
addFolder(driveOrDir, node, 0);
setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
* Recuperation des sous-elements d'un repertoire
* (avec niveau pour r�cursivit� et arr�t sur MAX_LEVEL)
* @param driveOrDir File
* @param node DefaultMutableTreeNode
* @param level int
private void addFolder(File driveOrDir, DefaultMutableTreeNode node, int level) {
File[] fileList;
fileList = driveOrDir.listFiles();
if (fileList != null) {
sortFiles(fileList); // on tri les elements
// on ne cherche pas plus loin que le niveau maximal d�finit
if (level > MAX_LEVEL - 1) {return;}
// pour chaque �l�ment
try {
for (int i = 0; i < fileList.length; i++) {
// en fonction du type d'�l�ment
if (fileList[i].isDirectory()) {
// si c'est un r�pertoire on cr�� un nouveau noeud
FSNode dir = new FSNode(fileList[i].getName(), fileList[i]);
node.add(dir);
// on recherche les �l�ments (r�cursivit�)
addFolder(fileList[i], dir, ++level);
if (fileList[i].isFile()) {
// si c'est un fichier on ajoute l'�l�ment au noeud
node.add(new FSNode(fileList[i].getName(), fileList[i]));
catch (NullPointerException e) {
// rien
* Recuperation des sous-elements d'un noeud
* @param node
public void addFolder(FSNode node) {
setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
for (int i = 0 ; i < node.getChildCount() ; i++) {
addFolder(((FSNode)node.getChildAt(i)).getFile(), (FSNode)node.getChildAt(i));
setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
* Tri une liste de fichier
* @param listFile
public void sortFiles(File[] listFile) {
triRapide(listFile, 0, listFile.length - 1);
* QuickSort : Partition
* @param listFile
* @param deb
* @param fin
* @return
private int partition(File[] listFile, int deb, int fin) {
int compt = deb;
File pivot = listFile[deb];
int i = deb - 1;
int j = fin + 1;
while (true) {
do {
j--;
} while (listFile[j].getName().compareToIgnoreCase(pivot.getName()) > 0);
do {
i++;
} while (listFile[i].getName().compareToIgnoreCase(pivot.getName()) < 0);
if (i < j) {
echanger(listFile, i, j);
} else {
return j;
* Tri rapide : quick sort
* @param listFile
* @param deb
* @param fin
private void triRapide(File[] listFile, int deb, int fin) {
if (deb < fin) {
int positionPivot = partition(listFile, deb, fin);
triRapide(listFile, deb, positionPivot);
triRapide(listFile, positionPivot + 1, fin);
* QuickSort : echanger
* @param listFile
* @param posa
* @param posb
private void echanger(File[] listFile, int posa, int posb) {
File tmpFile = listFile[posa];
listFile[posa] = listFile[posb];
listFile[posb] = tmpFile; -
HT2494 How do I output video to a projector from my MacPro17 with only firewire and USB ports?
How do I output video to a projector from my MacPro17 with only firewire and USB ports?
No Mac Pro only has Firewire and USB. Perhaps you've misidentified the computer:
http://www.everymac.com/ should help. -
how to take in videos, pictures nd songz from my pc to my ipad..???
You can copy videos, photos and music to a wireless flash drive and stream them to your iPad (it doesn't take up any space on your iPad.
http://www.sandisk.com/products/wireless/flash-drive/ -
How do I do SELECT * FROM TABLE WHERE KEY IN ({list})?
The title says it all really.
Is there a reasonable performant way to perform the query
SELECT * FROM TABLE WHERE KEY IN ({list})where {list} is String []?
I am currently creating a PreparedStatement with a for loop like this StringBuffer sb = new StringBuffer ("SELECT * FROM TABLE WHERE ID IN (");
for (int ii=0;ii<keys.length;ii++) {
sb.append (keys [ii]);
if (ii != keys.length-1) sb.append (",");
sb.append (")");but this means that the prepared statement is created each time I call my method and so I'm not sure that the optimizer will find it easy to cope with. Is there a construction that I'm missing along the lines of SELECT * FROM TABLE WHERE KEY = ? where I can create the PreparedStatement once and just call setObject or something on it when the values in {list} change?but this means that the prepared statement is created
each time I call my method and so I'm not sure that
the optimizer will find it easy to cope with.You are right, the optimizer won't find that easy to deal with (presuming that is even relevant for your driver/database.) But most optimizers won't do anything with statements that change and that is what you are doing.
You could create several prepared statements which have a common number of bind variables. For example 10 statements with from 1 to 10 bind values. This will work if most of the queries use those. -
How to convert select-options table into single field internal table
Hi,
My requirement is to convert select-options table into single internal table which has one field.
e.g. select-options: s_matnr for mara-matnr.
select-options table can have options 'BT',"EQ", "NE", "GE", "GT", "LE", "LT", "CP" etc. select-options table
have Sign:I ,Option:BT, Low: 1, High.10.The new internal table records should be 1,2,3,4,5,6,7,8,9,10.
Please suggest any function module available for this scenario in SAP.
Thanks,
Somi.
Edited by: somi reddy satti on Sep 15, 2009 3:18 PMHi Sowmya,
Here is the answer if I understand well of your question.
Data: begin of gt_mon OCCURS 0,
mon(2) TYPE n,
end of gt_mon.
Data: begin of gt_year OCCURS 0,
year(4) TYPE n,
end of gt_year.
Select-options: s_period FOR ptdw_pws_db-kmonth NO-EXTENSION
DEFAULT sy-datum(6)
TO sy-datum(6).
For example according to above statement period is 201110 is 201201.
Period field does n't exists in SAP for selection. If your selection is on date based on period which is given on the selection-screen then you need to convert the period to date by concatenating ( or using FM to convert )01 at the end of each period . You need to declare one range table for date to select the data from table.
loop at s_period.
gr_date-sign = s_period-sign.
gr_date-option = s_period-option.
COncatenate s_period-low
'01'
into gr_date-high.
COncatenate s_period-high
'01'
into gr_date-low
append gr_date.
ENDloop.
Thanks,
Satheesh -
Is select from view faster then select from table..???
Hello Gurus,
I want to query some data from two tables, both of table have many columns (attributes) and many rows...
I use several where clauses to retrieve data from those tables..
witch one is faster, I create a view or I just "select" from those tables???
Regards.
Nia...riedelme wrote:
3360 wrote:
riedelme wrote:
Selecting through a view almost never helps performance and frequently hurts.Views do not affect performance.
Views are simply queries and like queries there are fast and slow ones.I disagree.
First of all, to use a view you are executing a query to get a result set, then accessing the data from that result set - a built-in extra step to perform to get data.First of all that entire explanation of how views work is not correct. The optimizer will rewrite the query to make the view go away if possible.
SQL> create or replace view v as select * from dual;
View created.
SQL> explain plan for select * from dual where dummy = 'X';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 272002086
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DUMMY"='X')
13 rows selected.
SQL> explain plan for select * from v where dummy = 'X';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 272002086
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DUMMY"='X')
13 rows selected.Exactly the same.
>
Second, when accessing the data from the view the result sets don't have indexes for fast lookups and efficient joins on later steps.This is also known as just making stuff up and is not how the database works. care to share any references at all for any of this?
>
Third, the systems I've seen that use views extensively - I am looking at one now - tend to perform joins on views using the same tables with the same data over and over. This is a design issue and not specifically a problem with views but they lend themselves to this misuse much too easilyCorrect as I said a view is just a query, and just like queries there are good fast views and bad slow views
>
I'll concede that the problem is not specifically with views themselves but as I just said they lend themselves to misuse. Tuning views of views and views joined to views is difficultYes, queries can be misused as can almost all SQL functions and functionality.
As I said - Views are simply queries and like queries there are fast and slow ones.
Nothing that you have posted that is accurate changes that. -
URGENT : select from table statement in ABAP OO
Hi all,
I am an absolute ABAP OO beginner and need some quick help from an expert. How can I make a selection from an existing table (eg MARA) in an BADI which is programmed according to ABAP OO principles.
In the old ABAP school you could make a TABLES statement at the beginning and the do a SELECT¨* FROM but this does not work in ABAP OO.
How should i define such simple selections from existing tables. Anyone ?
Thanks a lot,
Eric Hassenberg*define internal table
data: i_mara like standard table of mara.
*select to this table
select * from mara into table i_mara.
Also you have to define work area for this internal table in order to use it.
data:w_mara like line of i_mara.
Maybe you are looking for
-
I am attempting to create a custom Purchase Order RTF Template (XMLP 5.5). I am making some progress, but I have come across a page formatting issue. Does anyone have an example on controlling the number of lines which appear on a Purchase Order page
-
How to reverse released payment request
I would like to inquire how to delete or reverse released payment request if the repetitive code at tcode OT81 has been deleted. The released payment request automatically disappeared from the list of released payment request at tcode frft_b. But whe
-
WDS??????
what is WDS? i get an error on my WLSE server saying ""AP is not registered with any WDS"" Do i need a WDS? If so could anyone send me to a good link about setting up a WDS........Thanks! James
-
Unkown error(-23) while trying to update to IOS5
It keep promptimg me than unknown error -(-23) while trying to update to IOS5, anyone has the same problem? Can anyone help to retify this problem?
-
Help needed.....FAQs
hi. i haf two qns.....firstly, is there a method that will help mi clear all the inputs the user key in using textfields?? Coz now mi hardcode all the textfields to set as null when mi click the clear button. Secondly, i have been working on Jtable u