Table name's suffix question
I notice some table have the suffix '_B' .
e.g: RA_TERMS_B
what's the special meaning of this suffix? what does 'B' stand for?
what's the relation between '_B' and '_TL' ?
thanks
Oracle Metalink describes this as "Separate LANGUAGE and SOURCE_LANG columns are required because Applications tables that need to store translations are organized into pairs: a base table, whose name typically (but not in every case) ends with "_B"; and a translation table, whose name ends with "_TL". For every row in the base table, there are "n" rows in the corresponding _TL table, where "n" is the number of enabled languages"
Edited by: pillair on Apr 15, 2009 1:48 AM
Similar Messages
-
PL/SQL cursor question (possible to pass in the table name?)
I want to pass the name of a table to a cursor and select from that,
Is this possible in PL/SQL?
CURSOR get_rows(table_name IN VARCHAR2) IS
SELECT * FROM table_name;
The actual sql statement that will be used is more complex.
I have 18 tables for which the same query would work varrying only in the name of the table.
I get an error when I try to do the above.>
I am not quite sure how you can derive anything from the design given the example that has all other details stripped out
>
What Justin said is pretty clear
>
If you are really doing a SELECT * and you have 18 different tables, it seems unlikely that all tables would always have exactly the same set of columns. If they do, that is almost certainly an indication that the data model is incorrect.
>
A data model that includes 18 tables with the same set of columns has something wrong with it. You explained that by clarifying that it is only TWO columns in each of the 18 tables that is the same. Perhaps the tables have one-to-many relationships and the two columns are the key columns. That is different.
>
The 'select *' will actually pull back only two columns, both of which are primary keys (long). I need to select all rows into a data structure that is global that I can iterate through at a later time. So given that I can use a ref cursor and have a dynamic table name, how would I select into a data structure that is of two primary keys and make that global to be used in another method at a later time?
>
Why not use an actual table to store the column data? An index-organized table would be perfect for that use and won't use up valuable user memory.
And by global do you mean the data needs to be accessible by a different session than the one that collected the data?
And what do you mean by 'later'? Tomorrow or next week?
The use case you describe sounds like you are having to update primary key values in tables that have parent-child foreign key constraints. Is that what you are doing? Can you do this offline and defer or disable the constraints, perform an update (rather than insert/delete) and then reenable the constraints? -
An sql question about table names
Is it possible to create a table with a certain name via programmatic manipulation using sql?
Here is my code, can you please tell me why it's not working, and if there is a way to make it work? I basicaly need to create tables with names corresponding to names in a vector.
public void files(){
try {
FileInputStream file = new FileInputStream("C:\\Documents and Settings\\Adham\\jbproject\\SeniorProject\\id.ser");
ObjectInputStream input = new ObjectInputStream(file);
val = (Vector)input.readObject();
input.close();
catch (java.io.IOException IOE) {
IOE.printStackTrace();
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
public void createtables()
{ files();
String dsn = "jdbc:odbc:etv";
String dbUser = "Adham";
String dbPass = "reqss";
for (int i = 0; i<val.size(); i++){
String s = val.elementAt(i).toString();
try {
Connection con = DriverManager.getConnection(dsn, dbUser, dbPass);
Statement stmt = con.createStatement();
String sql = new String("CREATE TABLE "+s + "(Start INTEGER,"+ "End INTEGER,"+ "Channel VARCHAR(255),"+ "Title VARCHAR(255))");
stmt.executeUpdate(sql);
stmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
return;
}your help is greatly appreciatedIt's not that you can't create a table at runtime. You can execute an UPDATE with CREATE TABLE in it.
I'm saying that the string you're passing in as the table name probably contains a lot more than just the name that you think it does. Print out that string before you execute the SQL and see what it has.
You're reading a serialized object stream. That has a lot more stuff in it than just the table name. I'm guessing that the SQL engine is seeing all that stuff and having a problem with it.
This code can create tables:
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class TableCreator
public static final String DEFAULT_SQL = "CREATE TABLE TEST(NAME TEXT(80))";
public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DATABASE = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Edu\\Java\\Forum\\DataConnection.mdb";
public static final String USERNAME = "admin";
public static final String PASSWORD = "";
public static void main(String [] args)
try
String tableCreationSQL = ((args.length > 0) ? args[0] : DEFAULT_SQL);
String driver = ((args.length > 1) ? args[1] : DRIVER);
String url = ((args.length > 2) ? args[2] : DATABASE);
String username = ((args.length > 3) ? args[3] : USERNAME);
String password = ((args.length > 4) ? args[4] : PASSWORD);
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
statement.executeUpdate(tableCreationSQL);
statement.close();
connection.close();
catch (ClassNotFoundException e)
System.err.println("Couldn't load JDBC driver class");
e.printStackTrace();
catch (SQLException e)
System.err.println("SQL state: " + e.getSQLState());
System.err.println("SQL error: " + e.getErrorCode());
e.printStackTrace();
catch (Exception e)
e.printStackTrace();
}Compile it and try it with your own database and creation SQL.
MOD -
Passing dynamic table name in ADO. net destination
I am new to SSIS and I have a requirement where i need to pass dynamic table name in ADO .net destination .
My package contains an "Execute Sql task" in the control flow which computes the destination table name to be provided at run time and stores it in a variable expression
"@[User::Table_name]"(which has a scope of full package).
Now, the problem I'm facing right now is that , I am unable to use this variable expression in the ADO .Net Destination .
I need to pass this variable expression as the table name in ado .net destination.
But, whenever I use this variable in place as the table name I keep on getting this error and my package fails:-
[ADO NET Destination [403]] Error: The Table or View name is not expected. \n\t If you are quoting the table name, please use the prefix " and the suffix " of your selected data provider for quotation. \n\t If you are using multipart name,
please use at most three parts for the table name.
Although ,I am able to run my package when i am providing the existing(static) table name.So there is nothing wrong with the package.
Tried a lot of things still not working..Please help...I am having the result stored in the variable expression . I just need a way to be able to use it as the Destination table in ADO .net Destination.
I am not sure if this will work for you, but I am able to store the table name in variable and use it dynamically (via data flow task expression property ) as shown.
Thanks, hsbal
Hi Adeep,
Based on my further research, just as hsbal said, we can set a variable as ADO.NET Destination table via Expressions property in Data Flow Task.
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Hello there,
I have a question on the following:
I want to read from a series of tables which a different suffix such as
table123, table234 and table110
How can I put them in a loop and extract data from them
for x in y loop
select abc, edf, .......
from tablexxx;
end loop;
I have tried the execute immediate command but the sql was loo long.
Anybody has any idea? Thanks in advance.I have tried the execute immediate command but the
sql was loo long.So you already know that if you have "dynamic" tables then you need "dynamic" sql.
It's at this point you should ask yourself if "dynamic" tables are really the best solution for your database design.
Clearly, any application written against the database needs to know what tables it is accessing and, likewise, this should make you think that it's perhaps a good idea that the tables are known at the time the application is designed.
What is your requirement for having tables with similar names but different suffix's?
The classic design fault is people who create seperate tables for certain time periods i.e. each month a new table is created for that month of that year. This of course leads to the problem of dynamic tables and dynamic queries.
In such a situation, the better design would be one of the following...
a) if you have the partitioning option on your oracle database, create your table with partitions for the required sub sets of data. Partitions can be added, truncated or removed without the table name changing. They can also help the queries to perform faster as the optimiser will be able to determine what partitions it needs to access to get the data.
b) if you don't have partitioning then consider including relevant columns in the table to provide the relevant sectioning of data. With suitable indexes this can be just as performant, even with a lot of data.
;) -
How get all table name from database
hi master
sir
how get all table name from databaseThe big question is 'why'.
Selecting from view 'dba_tables' will indeed give the list of all tables in the database, but that includes the dictionary tables and the internal tables, and many others that are probably not of interet to a person who needs to ask this question. Besides, the dba_tables view requires access to a DBA account.
There are several other views: "user_tables" will list all the tables in this user's schema; and "all_tables" will list all the tables this user can access in some way.
The above do not, of course, include any information about synonyms, sequences, views, indexes and so on.
The correct answer and the meaningful answer may be two different things. -
How-To Find the R/3 Table Name for a BW Data Source
Hi there,
Please advice how can I find the respective table name in R/3 for a particular BW DataSource ?
P/S : I would like a technical how-to instead of referring the table names at HELP.SAP.COM
For instance, for my Standard Business Content Info Cube 0CCA_C03(CO-OM-CCA: Statistical Key Figures) which extracts from BW Data Source: 0CO_OM_CCA_4
My question is, how can I find out which specific tables in SAP R/3 is this Data Source pulling the data from ?Hi Dinesh,
Data Source: 0CO_OM_CCA_4
1) In my R/3, I ran SE16 : Table -> ROOSOURCE
2) OLTPSOURCE -> 0CO_OM_CCA_4
3) EXMETHOD = F1
(Hence, I assume the Extraction Method is a Function Module)
4) So, Function Module = BWOM_RS_GET_CTRSTA
5) Run SE37 in R/3
How do I find out the specific tables in this Function Module ?
Would you please list them for me, so I can further refer to the individual tables ? -
How to get source table name according to target table
hi all
another question:
once a map was created and deployed,the corresponding information was stored in the repository and rtr repository.My question is how to find the source table name according to the target table,and in which table these records are recorded.
somebody help me plz!!
thanks a lot!This is a query that will get you the operators in a mapping. To get source and targets you will need some additional information but this should get you started:
set pages 999
col PROJECT format a20
col MODULE format a20
col MAPPING format a25
col OPERATOR format a20
col OP_TYPE format a15
select mod.project_name PROJECT
, map.information_system_name MODULE
, map.map_name MAPPING
, cmp.map_component_name OPERATOR
, cmp.operator_type OP_TYPE
from all_iv_xform_maps map
, all_iv_modules mod
, all_iv_xform_map_components cmp
where mod.information_system_id = map.information_system_id
and map.map_id = cmp.map_id
and mod.project_name = '&Project'
order by 1,2,3
Jean-Pierre -
Pass table name as parameter in prepared Statement
Can I pass table name as parameter in prepared Statement
for example
select * from ? where name =?
when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
Thanks
Haroon Idrees.haroonob wrote:
I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
Well, I would say (ugly as it is) String concatenation, or stored procedures. -
How To Find Out Table Name At Database Level Trigger
Table Name
How do I will come to know the name of table on which currently DML statement is fired ?
e. g. My current user is SCOTT. So Scott should realize the event of DML Statement fired. Hence my question is how the trigger on User Level is to be written & how to catch the event & table name on which the statement is being executed.
Suppose my table is as follows
Table Name : EMP
EMPNO number
ENAME varchar2(10)
JOB varchar2(9)
MGR number
HIREDATE date
SAL number
COMM number
DEPTNO number
Bcd number
Brcd number
Rec_id number
Scn_no number
Sequences for above table
1. EMP_REC_ID - minimum value is 1 increment by 1 & max value is unlimited
2. EMP_SCN_NO - minimum value is 1 increment by 1 & max value is unlimited
I have written a trigger as follows :
CREATE OR REPLACE TRIGGER UPD_EMP_REC_SCN BEFORE INSERT OR UPDATE OR DELETE ON EMP REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
DECLARE
BEGIN
IF (INSERTING) THEN
SELECT EMP_REC_ID.NEXTVAL INTO :NEW.REC_ID FROM DUAL;
ELSIF (UPDATING) THEN
SELECT EMP_SCN_NO.NEXTVAL INTO :NEW.SCN_NO FROM DUAL;
ELSIF (DELETING) THEN
INSERT INTO DELETED_ROWS (TAB_NAME, BCD, BRCD, REC_ID)
VALUES (‘EMP’, :OLD.BCD, :OLD.BRCD, :OLD.REC_ID);
END IF;
END;
Hence My problem is
If my database user contains 800 tables then I have to write down 800 triggers (i.e. for each table).
I want to write only one trigger at database level so that I can dynamically take actions, for this I need table name and the event on which the dml event has taken place.
Any help in this matter will be greatly appreceiated.
Regards
VikrantYou cannot write a single trigger that applies to multiple tables. If you need a trigger for every table, you will need to generate 800 triggers.
Rather than manually generating 800 triggers, you might write a code generator that generates triggers for each of the tables by querying the data dictionary (i.e. DBA_TABLES, DBA_TAB_COLS, etc).
Justin -
How to get the column name and table name from xml file
I have one XML file, I generated xsd file from that xml file but the problem is i dont know table name and column name. So my question is how can I retrieve the data from that xml file?
Here's an example using binary XML storage (instead of Object-Relational storage as described in the article).
begin
dbms_xmlschema.registerSchema(
schemaURL => 'my_schema.xsd'
, schemaDoc => xmltype(bfilename('TEST_DIR','my_schema.xsd'), nls_charset_id('AL32UTF8'))
, local => true
, genTypes => false
, genTables => true
, enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_CONTENTS
, options => dbms_xmlschema.REGISTER_BINARYXML
end;
genTables => true : means that a default schema-based XMLType table will be created during registration.
enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_CONTENTS : indicates that a repository resource conforming to the schema will be automatically stored in the default table.
If the schema is not annotated, the name of the default table is system-generated but derived from the root element name :
SQL> select table_name
2 from user_xml_tables
3 where xmlschema = 'my_schema.xsd'
4 and element_name = 'employee';
TABLE_NAME
employee1121_TAB
(warning : the name is case-sensitive)
To annotate the schema and control the naming, modify the content to :
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb">
<xs:element name="employee" xdb:defaultTable="EMPLOYEE_XML">
<xs:complexType>
Next step : create a resource, or just directly insert an XML document into the table.
Example of creating a resource :
declare
res boolean;
doc xmltype := xmltype(
'<employee>
<details>
<emp_id>1</emp_id>
<emp_name>SMITH</emp_name>
<emp_age>40</emp_age>
<emp_dept>10</emp_dept>
</details>
</employee>'
begin
res := dbms_xdb.CreateResource(
abspath => '/public/test.xml'
, data => doc
, schemaurl => 'my_schema.xsd'
, elem => 'employee'
end;
The resource has to be schema-based so that the default storage mechanism is triggered.
It could also be achieved if the document possesses an xsi:noNamespaceSchemaLocation attribute :
SQL> declare
2
3 res boolean;
4 doc xmltype := xmltype(
5 '<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:noNamespaceSchemaLocation="my_schema.xsd">
7 <details>
8 <emp_id>1</emp_id>
9 <emp_name>SMITH</emp_name>
10 <emp_age>40</emp_age>
11 <emp_dept>10</emp_dept>
12 </details>
13 </employee>'
14 );
15
16 begin
17 res := dbms_xdb.CreateResource(
18 abspath => '/public/test.xml'
19 , data => doc
20 );
21 end;
22 /
PL/SQL procedure successfully completed
SQL> set long 5000
SQL> select * from "employee1121_TAB";
SYS_NC_ROWINFO$
<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceS
<details>
<emp_id>1</emp_id>
<emp_name>SMITH</emp_name>
<emp_age>40</emp_age>
<emp_dept>10</emp_dept>
</details>
</employee>
Then use XMLTABLE to shred the XML into relational format :
SQL> select x.*
2 from "employee1121_TAB" t
3 , xmltable('/employee/details'
4 passing t.object_value
5 columns emp_id integer path 'emp_id'
6 , emp_name varchar2(30) path 'emp_name'
7 ) x
8 ;
EMP_ID EMP_NAME
1 SMITH -
Field symbols as Table name and in where condition in a select statement
Hello All,
I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
Here is my code:
DATA: TAB LIKE SY-TNAME,
TAB_COMP1 LIKE X031L-FIELDNAME,
TAB_COMP2 LIKE X031L-FIELDNAME,
NO_OF_FLD TYPE N.
DATA: BEGIN OF BUFFER,
ALIGNMENT TYPE F,
C(8000) TYPE C,
END OF BUFFER.
FIELD-SYMBOLS: <WA> TYPE ANY,
<COMP1> TYPE ANY,
<COMP2> TYPE ANY.
GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
TAB = TAB_NAME.
CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
CASE TAB_NAME.
WHEN 'OIUH_RV_GL'.
KEY FIELD
TAB_COMP1 = 'GL_GL_SYS_NO'.
NO_OF_FLD = 1.
WHEN 'OIUH_RV_OPSL'.
KEY FIELD
TAB_COMP1 = 'OPSL_GL_SYS_NO'.
NO_OF_FLD = 1.
WHEN 'OIUH_RV_OTAX'.
NOT THE ONLY KEY FIELD
TAB_COMP1 = 'OTAX_GL_SYS_NO'.
TAB_COMP2 = 'OTAX_TAX_POS_NO'.
NO_OF_FLD = 2.
WHEN 'OIUH_RV_GTAX'.
NOT THE ONLY KEY FIELD
TAB_COMP1 = 'GTAX_GL_SYS_NO'.
TAB_COMP2 = 'GTAX_TAX_POS_NO'.
NO_OF_FLD = 2.
WHEN OTHERS.
EXIT.
ENDCASE.
SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
How to add where clause and remove the if condition in the select -- endselect
SELECT * FROM (TAB) INTO <WA>.
ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
IF NO_OF_FLD = 2.
ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
ENDIF.
IF <COMP1> = OLD_SYS_NO.
code for updating table would come here
WRITE: 'MATCH FOUND'.
EXIT.
ENDIF.
ENDSELECT.
Please advice. Thanks much.
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM1. Create single column table for holding field name depending on the table entered.
2. Take input from user: for e.g. table_name
3. Using case load single column table with required fields
for e.g.
CASE TAB_NAME.
WHEN 'OIUH_RV_GL'.
Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
WHEN 'OIUH_RV_OPSL'.
Append 'OPSL_GL_SYS_NO'.
WHEN 'OIUH_RV_OTAX'.
Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
WHEN 'OIUH_RV_GTAX'.
Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
WHEN OTHERS.
EXIT.
ENDCASE.
Now depending on the table name you have required column ready
4. Create dynamic internal table using following sudo code
Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
loop at internal table with all the fields.
move it to field catalog.
append field catalog.
endloop.
5. Pass this field catalog table to static method create_dynamic_table method
DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = fieldcatalog_tab
importing
ep_table = table.
6. Now assign table reference to field symbol of type table.
ASSIGN table->* to <field-tab>.
7. Also create work area <field-wa> using refrence of table.
create data object wa LIKE LINE OF <field-tab>.
ASSIGN wa->* to <field-wa>.
8. Also define field symbol for field name.
for e.g. <field_name>
4. Dynamic internal table is ready
5. Now execute the select statement as follows:
SELECT (KEY_FIELD)
INTO <ITAB> --> created dynamically above
FROM (TABLE_NAME)
WHERE (WHERE). --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
In this case you need to append all your where condition line by line in to WHERE.
5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
loop at internal table containing list of fields into field_wa --> single column field table
ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
Move <your_new_value> to <field-name>. --> Assign new value
or
<field-name> = <your_new_value>.
Endloop.
6. After completing all the fields one row will be ready in <field_wa>.
APPEND <field_wa> to <field_tab>.
Hope this helps you.
Thanks,
Augustin. -
Dears,
What is the table name for On-Hand Quantity under Distribution_Inventory Super Users Irresponsibility ???ahmad wrote:
Dears,
What is the table name for On-Hand Quantity under Distribution_Inventory Super Users Irresponsibility ???This question was asked many times in the forum before, please see old threads for details.
https://forums.oracle.com/forums/search.jspa?threadID=&q=259722.1&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
https://forums.oracle.com/forums/search.jspa?threadID=&q=Determine+AND+Table+AND+Name&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
Table name input. and output i need all rows and columns using procedures
hi,
question: table name input. and output i need all rows and columns by using procedures.
thanks,
To AllAn example of using DBMS_SQL package to execute dynamic SQL (in this case to generate CSV data in a file)...
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
,p_dir IN VARCHAR2
,p_header_file IN VARCHAR2
,p_data_file IN VARCHAR2 := NULL) IS
v_finaltxt VARCHAR2(4000);
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
v_fh UTL_FILE.FILE_TYPE;
v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
END CASE;
END LOOP;
-- This part outputs the HEADER
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
FOR j in 1..col_cnt
LOOP
v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
IF NOT v_samefile THEN
UTL_FILE.FCLOSE(v_fh);
END IF;
-- This part outputs the DATA
IF NOT v_samefile THEN
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
END IF;
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
v_finaltxt := NULL;
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
ELSE
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
END CASE;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
END LOOP;
UTL_FILE.FCLOSE(v_fh);
DBMS_SQL.CLOSE_CURSOR(c);
END;This allows for the header row and the data to be written to seperate files if required.
e.g.
SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
PL/SQL procedure successfully completed.Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
Adapt to output different datatypes and styles are required. -
Table name for shipping details for the given purchase order
Hi,
Table name for shipping details for the given purchase order
regards,
vijayHad anybody seen that this question was raised 5 years ago?
And the question was about where are the shipping details of a purchase order stored.
The discussion owner hat marked the the discussion a year ago as solved, but did not mark any correct answer and did not tell himself what the solution was.
The correct answer was given by Amitkumar yesterday, it is EKPV
I am locking the discussion to avoid that even more wrong answers are added to this particualr question
Maybe you are looking for
-
Hi, I am from the UK, I filmed some DVCAM footage in PAL format, but bringing it into FCP to output onto NTSC and onto DVD for a Canadian conference / Broadcast. Can i simply change my project and capturing settings to get the footage to run at NTSC
-
i can't use facetime in my 4s. help me please.
-
Up until recently, I would use iWeb to create web pages or a web-site, then give it to someone else to upload on their GoDaddy account. My "uploader" contact has since sold his business and I have some of his GoDaddy accounts dumped into my lap. Ther
-
ACE ACS TACACS+ Key Mismatch issue
Goodday, I have an issue when trying to setup ACE Modules for TACACS+ and AAA autentication whereby the Failed Authentication reports, state the reason as "Key Mismath". We have confirmed that the key we are using is the same on the ACE and on the AC
-
Leopard trash hangs; repair permission slow, time capsule erased
since i have installed my leopard upgrade in order to install my time capsule, trash hard to empty and repairing permissions deletes my time capsule backup and capsule says i have no backup (which, when you do your first, it takes 24 hours, so it is