[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

How Can I write a PL/SQL routine that will generate a "CREATE TABLE" that will populate the table name from a value in existing table?

Asked by nbuch in PL / SQL, Oracle Database, Oracle 10.x

Tags: sql, oracle, table

Hello,
I am sort of a newbie writing code in SQL*PLUS and PL/SQL, but I do have extensive programming exerience with VB, SQL Server, MS Access.

I have been given a task to programmatically dynamically create tables through using SQL statements OR some type of oracle procedure that will look at existing tables and extract values from the main table to give the NEW TABLE NAMES and table structure through code. I think once I get this started I can complete this task on my own hopefully :).

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
---The only columns and datatypes are to be hardcoded that will be inserted into each new table structure are below:
This is example of a SQL statement to hard code the columns NAME AND DESCRITION.
 
PLEASE NOTE: OBJ_TYPE_NAMES ARE IN THE obj_type TABLE ONLY****
SQLstatement = "create table" + obj_type_nm 	
SQLstatement = SQLstatement " "\n" + "("
SQLstatement = SQLstatement " "\n" + "name		varchar2(100)	not null,"
SQLstatement = SQLstatement " "\n" + "description	varchar2(400)	null"
 
The CODE should work like this:
 
Loop through each existing table and first find the NEW TABLE NAME from the OBJ_TYPE Table which would be 
<DESIGN_SPECIFICATION> Based on THE FIRST ID NUMBER "OBJ_TYPE_ID" = 1
 
Then the code should find the NEXT TABLE "OBJ_TYPE_RLTNSHP" and extract the COLUMN value from the column named
OBJ_TYPE_NM based on the OBJ_TYPE_ID  = 1 WHICH WOULD BE in this case <DATA TYPE>
 
Then the code should go to the last table based on the same parameters in the next table "PRPRT" and 
extract the column value from the column name "prt_nm" where OBJ_TYPE_ID =1 which would be in this case <ERP_NO>
and so forth, this is just and EXAMPLE 
 
***PLEASE FEEL FREE TO CHANGE THE SQL statements, I was just trying to figure out a way to hard code the name and description columns since they should generate in every table.
 
 
 
These are the EXISTING TABLES which we will be extracting the NEW table NAME and columns, datatypes and attributes.
 
Table Name: Obj_Type
 
Coulumn1	Column2
Obj_type_ID	Obj_type_nm
1		Design_Specification
2		Attribute
3		Entity
 
 
Table Name:OBJ_TYPE_RLTNSHP
Column1		Column2		Column3
OBJ_TYPE_ID	Data Type	Obj_type_mndtry_in
1		FK		String
2		PK		String
3		REQUIRED	Number
 
Table Name: Prprt
Column1:	Column2		Column3
prt_id		prt_nm		prt_size
1		erp_no		100
2		release		200
3		version		50
 
--Results of the Create Table STATEMENTS would return a table structure similar below:
 
Create Table Data_Specification
 
Name		Varchar(200)		not null,
Description	varchar2(400)		null,
Data Type	String(20)		not null,
FK		String(1)		not null,
PK		String(1)		not null,
Required	string(1)		not null
);
 
Create Table Attribute
Description	varchar2(400)		null,
Data Type	String(20)		not null,
ERP_NO		String(100)		not null,
Release		String(200)		not null,
Version		String(50)		not null,
);
[+][-]12/01/07 11:10 AM, ID: 20388958Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/01/07 05:14 PM, ID: 20389961Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/01/07 07:17 PM, ID: 20390193Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/01/07 10:18 PM, ID: 20390412Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/02/07 04:48 AM, ID: 20390918Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/02/07 12:20 PM, ID: 20392186Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/02/07 02:03 PM, ID: 20392516Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/03/07 06:08 AM, ID: 20395413Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/03/07 06:36 AM, ID: 20395610Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/03/07 08:11 AM, ID: 20396322Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/03/07 08:25 AM, ID: 20396457Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/05/07 06:46 AM, ID: 20411541Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/05/07 07:01 AM, ID: 20411673Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PL / SQL, Oracle Database, Oracle 10.x
Tags: sql, oracle, table
Sign Up Now!
Solution Provided By: jinesh_kamdar
Participating Experts: 2
Solution Grade: A
 
[+][-]12/05/07 08:30 AM, ID: 20412666Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09/04/08 04:00 PM, ID: 22393697Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/10/08 04:36 PM, ID: 22444194Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628