473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Help w/ SQL / Oracle - Building Tables?

Hi,

I am new to SQL, taking a course at a State University. I am building a database and would like to have my Owner_ID field come from automatically taking the first 2 letters of that records Last_Name field and 5 random numbers (generated automatically from the system) (example: db43679).

Name Null? Type
OWNER_ID NOT NULL VARCHAR2(7)
FIRST_NAME NOT NULL CHAR(20)
LAST_NAME NOT NULL CHAR(20)
SALUTATION CHAR(4)
STREET VARCHAR2(20)

Is this possible? If so, could someone please assist?

To reemphasize...I am very new to SQL, so keeping it as simpl, yet specific, as possible would be VERY helpful.

Thank you,
MsReece
Nov 25 '06 #1
4 1556
ronverdonk
4,258 Expert 4TB
If you want help with Oracle (see thread subject) you are in the wrong forum. I'll transfer you.

Ronald :cool:
Nov 25 '06 #2
OK...thank you!
Ms Reece

If you want help with Oracle (see thread subject) you are in the wrong forum. I'll transfer you.

Ronald :cool:
Nov 26 '06 #3
milonov
32
Hello,
the main scenario:

1) create sequence to generate 5 numbers:

Expand|Select|Wrap|Line Numbers
  1. create sequence s_seq
  2. minvalue 1
  3. maxvalue 999999999999999999999999999
  4. start with 10001
  5. increment by 1
  6. cache 20
  7.  
2)create trigger before insert each row to fill OWNER_ID:

Expand|Select|Wrap|Line Numbers
  1. create or replace trigger TBI_YOURTABLE
  2.   before insert on YOURTABLE
  3.   for each row
  4. declare
  5. var_owner_id varchar2(50);
  6. seq_number number;
  7. begin
  8.  
  9.   select s_seq.nextval into seq_number from dual;
  10.   var_owner_id := substr(:new.LAST_NAME, 1, 2) || to_char(seq_number);
  11.   select var_owner_id into :new.OWNER_ID from dual;
  12.  
  13. end TBI_YOURTABLE;
  14.  
  15.  
Best Regards,
Michael Milonov
http://www.snotratech.com

Hi,

I am new to SQL, taking a course at a State University. I am building a database and would like to have my Owner_ID field come from automatically taking the first 2 letters of that records Last_Name field and 5 random numbers (generated automatically from the system) (example: db43679).

Name Null? Type
OWNER_ID NOT NULL VARCHAR2(7)
FIRST_NAME NOT NULL CHAR(20)
LAST_NAME NOT NULL CHAR(20)
SALUTATION CHAR(4)
STREET VARCHAR2(20)

Is this possible? If so, could someone please assist?

To reemphasize...I am very new to SQL, so keeping it as simpl, yet specific, as possible would be VERY helpful.

Thank you,
MsReece
Nov 26 '06 #4
Thank you, Michael! I will try this.

Ms Reece

Hello,
the main scenario:

1) create sequence to generate 5 numbers:

Expand|Select|Wrap|Line Numbers
  1. create sequence s_seq
  2. minvalue 1
  3. maxvalue 999999999999999999999999999
  4. start with 10001
  5. increment by 1
  6. cache 20
  7.  
2)create trigger before insert each row to fill OWNER_ID:

Expand|Select|Wrap|Line Numbers
  1. create or replace trigger TBI_YOURTABLE
  2.   before insert on YOURTABLE
  3.   for each row
  4. declare
  5. var_owner_id varchar2(50);
  6. seq_number number;
  7. begin
  8.  
  9.   select s_seq.nextval into seq_number from dual;
  10.   var_owner_id := substr(:new.LAST_NAME, 1, 2) || to_char(seq_number);
  11.   select var_owner_id into :new.OWNER_ID from dual;
  12.  
  13. end TBI_YOURTABLE;
  14.  
  15.  
Best Regards,
Michael Milonov
http://www.snotratech.com
Nov 26 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: new_GUY | last post by:
I have a HUGE project (at least for me) and need some guidance. I am trying to create a database for a local university movie club that allows users to input there basic personal information...
1
by: Nikola Pecigos | last post by:
Hi, I have the following problem: We have an Oracle 9.2 with one table "document" which contains a path to the filesystem. If I want to index these files (HTML, PDF, World, Excel, etc.), I...
14
by: Sudhesh Nayak | last post by:
Hi, I have an Oracle (8.1) & a SQL Server 2000 database with Production data. There are situations when I need data from both the databases. My first choice was to link Oracle to SQL and run DTS...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
9
by: AnandaSim | last post by:
Hi All, I've had Access 97, 2000 connections to the corporate Oracle database for a few years now - but seldom use it. When I did use it years ago, performance was not fast but the features were...
2
by: phantom | last post by:
Hi all. We have a production data source running postgres for reporting/DSS we are thinking on building a warehouse, wherein data would be transferred from postgres to the warehouse. The...
2
by: egoldthwait | last post by:
I need to convert a 17mb access 2000 db to Oracle and house it in a Citrix farm. The issue: we have never converted an Access Db to Oracle but can probably use Oracle's Workbench to assist with...
27
by: Nasir | last post by:
Hi there, Is it posible to set the collation of SQL server 2005 like Oracle, which is that objects names and column names are case-insensitive, but data is sensitive;e.g: In Oracle: --create...
3
by: RLN | last post by:
Re: Access 2003/Oracle 9i I have an Access app that connects to an Oracle DB via OLEDB/VBA code (no DSN or ODBC) Queries against straight Oracle tables run fine. For this query, however,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.