الانتقال إلى المحتوى

إخواني ممكن تساعدوني في مشكلة Query


sunfoor

Recommended Posts

السلام عليكم

انا عندي قاعدة بيانات لشركة تأجير معدات وهي تحتوي على 9 جداول تقريبا والمطلوب عمل query لعرض أسماء الزبائن الذين استأجروا معدات الجداول المرتبطة هي (customer , reservation,equipment (
الجداول هي :
Customer

select * from customer;

CUSTOMERID CUSTOMERNAME CUSTOMERADDRESS
---------- ------------------------------ ------------------------------
CUSTOMERT CUSTOMEREMAIL
--------- --------------------------------------------------
100 Ali Ruwi
24811221 [email protected]

101 Samee Al kuwer
24861012 [email protected]

102 Yusof Darsait
992083141 [email protected]


CUSTOMERID CUSTOMERNAME CUSTOMERADDRESS
---------- ------------------------------ ------------------------------
CUSTOMERT CUSTOMEREMAIL
--------- --------------------------------------------------
103 Yahya Wadi alkabier
99123456 [email protected]


Reservation

[يسار][/left]

select * from reservation;

RESERVATIONNO REQUEST_P REQUEST_R CUSTOMERID EMPLOYEEID EQUIPMENTID
------------- --------- --------- ---------- ---------- -----------
200 10-MAY-09 05-MAY-09 100 300 111
201 20-MAY-09 26-MAY-09 101 302 112
202 24-JUN-09 26-JUN-09 102 303 113
203 27-JUN-09 30-JUN-09 103 304 113

جدول equipment

[/يسار]


SQL> select * from equipment;

EQUIPMENTID EQUIPMENTS RENTALCOUNT EQUIPMENTTYPE
----------- ---------- ----------- -------------
111 Rented 1 10
112 Rented 1 11
113 Rented 2 12
114 Not Rent 0 13
115 Not Rent 0 14

Query :

SQL> select customerID,customerName,customeraddress,reservationNo,equipmentID
2 from customer join Reservation
3 On customer.customerID=reservation.customerID;
select customerID,customerName,customeraddress,reservationNo,equipmentID
*
ERROR at line 1:
ORA-00918: column ambiguously defined

عطاني error ليش كل شي تمام priamary ke & forign key ??????
ارجوكم ردوا علي لأن البحث مطلوب مني أخلص بأسرع وقت :)
أختكم في الله :sunfoor
تم تعديل بواسطة sunfoor
رابط هذا التعليق
شارك

  • الردود 25
  • البداية
  • اخر رد

أكثر المشاركين في هذا الموضوع

  • sunfoor

    15

  • Amgad

    3

  • mw_wageeh

    3

  • mustafagamiel

    2

أكثر المشاركين في هذا الموضوع

الحمد لله جربت الكود واشتغل..

ألحين واجهتني مشكلة ثانية في جدول Rental_Equipment في عملية insrt data لمن ادخل بيانات في الجدول يعطيني error مع اني متأكدة من فورمات التاريخ
المسج هو :

[يسار][/يسار]
SQL> desc rental_equipment;
Name Null? Type
----------------------------------------- -------- ----------------------------
RENTALID NOT NULL NUMBER(4)
RENTALDATE DATE
RESERVATIONNO NUMBER(4)
CHECK_OUT_DATE DATE
RENTAL_PERIOD NUMBER(2)
DUE_DATE DATE
DEPOSIT_AMOUNT NUMBER(6)
RETURN_DATE DATE
RETURN_TIME TIMESTAMP(6)
RENTAL_CHARGE NUMBER(6)
LATE_FEE_CHARGE NUMBER(6)
INSPECTION_STATUS VARCHAR2(10)
MONIESKEPT NUMBER(6)
REASON VARCHAR2(20)
EMPLOYEEID NUMBER(3)

SQL> insert into rental_equipment values(400,'02-may-2009',200,'02-may-2009',3,'05-may-2009',15,'06-may-2009','10:00',5,1,'damaged',2,'full damage',300);
insert into rental_equipment values(400,'02-may-2009',200,'02-may-2009',3,'05-may-2009',15,'06-may-2009','10:00',5,1,'damaged',2,'full damage',300)
*
ERROR at line 1:
ORA-01843: not a valid month


SQL> insert into rental_equipment values(400,'02-may-2009',200,'01-may-2009',3,'05-may-2009',15,
2 '06-may-2009','10:00',5,1,'damaged',2,'full damage',300);
'06-may-2009','10:00',5,1,'damaged',2,'full damage',300)
*
ERROR at line 2:
ORA-01843: not a valid month

أنتظر الرد أرجوكم.

رابط هذا التعليق
شارك

السلام عليكم
المشكلة بس خاصة بال nls_date_format
لمعرفة ذلك يمكنك عمل كده

select sysdate from dual;


وتشوفي شكل التاريخ أه الاي ظهر وأدخلي البيانات بنفس الطريقة
يعني ممكن يظهر الشهر بالارقام وليس بالحروف
وبناءا عليه أدخلي الشهر باالارقام وهكذا

رابط هذا التعليق
شارك

شكرا على الرد

بس انا دخلت نفس الفورم للتاريخ في جدول أخر وعادي اشتغل !!!
جدول اسمه reservation :

[يسار][/يسار]select * from reservation;

RESERVATIONNO REQUEST_P REQUEST_R CUSTOMERID EMPLOYEEID EQUIPMENTID
------------- --------- --------- ---------- ---------- -----------
200 10-MAY-09 05-MAY-09 100 300 111
201 20-MAY-09 26-MAY-09 101 302 112
202 24-JUN-09 26-JUN-09 102 303 113
203 27-JUN-09 30-JUN-09 103 304 113
هذا مثال لبيانات الجدول

رابط هذا التعليق
شارك

شكرا على الرد اخوي

راح ادخل البيانات مثل ما كتبت وإن شاء الله تضبط هذي المرة .

سؤال : أريد أحذف عمودين من هذا الجدول وهما : check_out_date & Retrun_time ما اشوف لهم لزمة كيف يكون command?

رابط هذا التعليق
شارك

:) مشكورين إخواني

 

ألحين بعد ما أدخل البيانات في جدول Rental_equipment

يحتاج بعض الأعمد ادخل فيها zero مثلا العمود Return Date لأن مطلوب مني عمل query يطلب قائمة المعدات التي لم تسترجع إلى الآن :

 

Print a list of equipment that has not yet been returned by customer ????

 

شو لازم أعمل ؟

انتظر الرد

رابط هذا التعليق
شارك

اخواني انا دخلت البيانات في جدول ال rental_equipment والحمد لله

عندي query يطلب فيه عمل viwe table ما بين جدولين هما : employee and sales
بعد ما كتبت ال qeury طلع لي error وما اشتغل
هو كالتالي:

select * from employee ;

EMPLOYEEID EMPLOYEENAME         EMPLOYEEJOB          EMPLOYEEP                  
---------- -------------------- -------------------- ---------                  
      300 Hassan               Sales man            991112540                  
      302 Laila                Sales women          991122331                  
      303 Mohamed              Sales man            992020301                  
      304 Rasha                Sales women          996868686                  
      305 Ahmed                Sales man            99208850                   
      306 Nada                 Sales women          962211550                  

6 rows selected.

SQL> select * from sales; SALESID SALESDATE BUYERNAME            EMPLOYEEID                            
---------- --------- -------------------- ----------                            
      500 20-MAY-09 Amgad                       300                            
      501 26-JUN-09 Sawsan                      302                            
      502 01-AUG-09 Fatmah                      303                            

SQL> select * from sales_equipment; SALESID EQUIPMENTID NO_OF_EQUIPMENT SALES_CHARGE                             
---------- ----------- --------------- ------------                             
      500         111               1            7                             
      501         112               2           10                             
      502         113               2           15                             

SQL> create viwe viwe_employee as select employee.employeeid,employee.employeejob,employee.employeename,sales.salesid
 2  from Employee,sales 3  where employee.employeeid=sales.employeeid;
create viwe viwe_employee as select employee.employeeid,employee.employeejob,employee.employeename,sales.salesid
      *
ERROR at line 1:
ORA-00901: invalid CREATE command

يا ترى شو هي المشكلة؟؟
انتظر الرد ارجوكم
اختكم : sunfoor

رابط هذا التعليق
شارك

السلام عليكم

الخطأ فى كلمة view

create VIEW viwe_employee as select employee.employeeid,employee.employeejob,employee.employeename,sales.salesid
 from Employee,sales where employee.employeeid=sales.employeeid;



يمكنك مراجعة هذا الرابط بالمنتدى عن اوامر ال VIEW

إضغط هنا

رابط هذا التعليق
شارك

اخواني عملت تريجر لأول مرة في حياتي والمصيبة انه ما رضى يطلع من نطاق التريجر يعني مثلا
create or replace triggrt count-tg
after insert on reservation
for each row
begin
update equipment
set rentalcount=rentalcount+1
where equipmentid=:new.equipmentid;
end;

وبس وظل الترقيم التسلسلي للأوركل مستمر يعني اريد ارجع الى SQL prompt ????!!! ما يرضى حاولت بكل الأوامر ما في فايدة

انتظر الرد ارجوكم









ا

رابط هذا التعليق
شارك

لمن كتب التريجر حدث معي ذلك !!!

[يسار][/يسار] create Or replace Trigger count_Tg
2 after insert on Reservation
3 For each row
4 Begin
5 update equipment
6 set rentalcount=rentalcount+1
7 where equipmentid=:New.equipmentid;
8 End;
9
10
11
12
13
14 end;
15
16
17
18
19
وهكذا ... وعمل stuck

رابط هذا التعليق
شارك

مرحبا اخواني ما رديتوا علي أنتظركم .. :)

واجهتني مشكلة ثانية query
المطلوب عرض عدد المعدات التي تم استئجارها من قبل الزبون : Give the number of equipment rented by each customer

the Query is :

[يسار][/يسار]SQL> select count(equipmentid),customerid
2 from equipment,reservation
3 where equipment.equipmentid=reservation.equipmentid
4 group by customerid;
select count(equipmentid),customerid
*
ERROR at line 1:
ORA-00918: column ambiguously defined

شو معنى هذا ال error ??

اختكم : sunfoor

رابط هذا التعليق
شارك

الخطأ يعنى وجود نفس اسم العمود فى الجدولين ... ولذلك يجب وضع مميز قبل اسم العمود فى الامر المكتوب

ORA-00918: column ambiguously defined


Cause: A column name used in a join exists in more than one table and is thus referenced ambiguously. In a join, any column name that occurs in more than one of the tables must be prefixed by its table name when referenced. The column should be referenced as TABLE.COLUMN or TABLE_ALIAS.COLUMN. For example, if tables EMP and DEPT are being joined and both contain the column DEPTNO, then all references to DEPTNO should be prefixed with the table name, as in EMP.DEPTNO or E.DEPTNO.
Action: Prefix references to column names that exist in multiple tables with either the table name or a table alias and a period (.), as in the examples above.




http://ora-918.ora-code.com/

يمكن التعديل كالتالي

select count(E.equipmentid),R.customerid
 from equipment E ,reservation R
where equipment.equipmentid=reservation.equipmentid
group by customerid;



or

select count(equipmentid),customerid
 from reservation group by customerid;

تم تعديل بواسطة Ahmed_oracle
رابط هذا التعليق
شارك

مشكور اخوي أحمد على الرد ..
يعني كل زبون كم مرة استأجر معدة .صح؟

طيب اخوي احمد ما شوفت لي مشكلة triggrer ارجوك اريد الحل في اقرب وقت ممكن

انتظر الحل لأن عندي تريجير ثاني اريد أعمله.. فلازم اشغل الول حتى اقدر اشغل الثاني

sunfoor

رابط هذا التعليق
شارك

يجب بعد كتابة اوامر انشاء التريجير .... يجب كتابة حرف ال semi column ;
وكتابة حرف /
للرجوع لعلامة ال

sql)



وان تظهر رسالة
Trigger created.
للدلاله على نجاح عملية انشاء التريجير

تم كتابة الاوامر على اسماء الاعمدة والجداول التى انشأتها فى بداية المشروع
يمكنك تعديل هذه الاسماء طبقا لما لديك من اسماء جديده
يجب حذف ارقام الاسطر من المثال التالى 1-2-3-4-5-6-7-8-9

SQL> create Or replace Trigger count_Tg
 2  after insert on EQUIPMENT_RESERVATION
 3  For each row
 4  Begin 5  update equipment
 6  set rental_counts = rental_counts + 1
 7  where equipment_id = :new.equipment_id ;
 8  end;
 9  /

Trigger created.



امر لمعرفة العداد فى الجدول وهو يساوى = 1 قبل تنفيذ امر اضافة سجل جديد RENTAL_COUNTS
-------------------------------------------------------------

SQL> select * from EQUIPMENT; EQUIPMENT_ID EQUIPMENT_TYPE E RENTAL_COUNTS
------------ -------------- - -------------
        123             11 0             1



أمر اضافة سطر لحجز معدة ( وليس ايجار فعلي) فى جدول الحجوزات
-------------------------------------------------------

SQL> insert into EQUIPMENT_RESERVATION values ( 113,1,123,'11-jun-2009','22-jun-2009',1) ;

1 row created.



الاستعلام عن القيمة فى العداد بعد تنفيذ امر الاضافة اصبح = 2
------------------------------------------------------------------------------------

SQL> select * from EQUIPMENT; EQUIPMENT_ID EQUIPMENT_TYPE E RENTAL_COUNTS
------------ -------------- - -------------
        123             11 0             2


-------------------------------------------------

يمكن مراجعة هذا الرابط

إضغط هنا : الدرس الثاني عشر: انشاء التريجر على قاعدة البيانات, ضمن سلسلة دروس كيف تبدأ في تعلم الأوراكل

رابط هذا التعليق
شارك

جزاك الله ألف خير ......اخوي امجد

اشتغل التريجير وجربته والحمد لله تمام

ألحين عملت تريجير ثاني وهو الي عطيتني اياه سابقا ولكن لم يشتغل يعين ظهر لي error
Trggier
[يسار][/يسار]SQL> select * from sales_equipment;

SALESID EQUIPMENTID NO_OF_EQUIPMENT SALES_CHARGE
---------- ----------- --------------- ------------
500 111 1 7
501 112 2 10
502 113 2 15

SQL> create or replace trigger equipment_sold
2 After insert or delete ON sales_equipment
3 For each row
4 Begin
5 If inserting then
6 update equipment
7 set equipmentstatus='Sold'
8 where equipmentid=:New.equipmentid;
9 ElSIF Deleting then
10 update equipment
11 set equipmentstatus='Cancel'
12 where equipmentid=:old.equipmentid;
13 endif;
14 end;
15 /

Warning: Trigger created with compilation errors.

SQL> show err;
Errors for TRIGGER EQUIPMENT_SOLD:

LINE/COL ERROR
-------- -----------------------------------------------------------------
11/4 PLS-00103: Encountered the symbol ";" when expecting one of the
following:
if

رابط هذا التعليق
شارك

الخطأ فى كلمة endif المتصلة
يتم استبدالها ب
end if
وضع مسافة بين ال end if

1  create or replace trigger equipment_sold
 2   After insert or delete ON SALES_EQUIPEMENTS
 3    For each row
 4   Begin 5    If inserting then
 6    update equipment
 7    set EQUIPMENT_STATUS='S'
 8    where EQUIPMENT_ID=:New.EQUIPMENT_ID;
 9    ElSIF Deleting then
10    update equipment
11    set EQUIPMENT_STATUS='C'
12    where EQUIPMENT_ID=:OLD.EQUIPMENT_ID;
13    end if;
14*   end;
SQL> /

Trigger created.

SQL>

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   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

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

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

جاري التحميل



×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية