1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Need help by a simple script but im beginner with oracle

Discussion in 'SQL PL/SQL' started by Homam Alkurdy, Aug 26, 2016.

  1. Homam Alkurdy

    Homam Alkurdy Active Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Hamburg
    Hallo,
    I have a work sheet i have to do it and i began learning oracle just since 2 weeks ago so what i have to do is to create a tabel with two columns (Num and Value)
    Num must automatic filled from 1 to N
    Value must automatic filled with a random numbers
    With a parameter that N = max value
    So if anybody can help me i will appreciate that.
    Im using oracle 12.6
    Thank you
    Homam
     
  2. krasnoslobodtsev_si

    krasnoslobodtsev_si Forum Genius

    Messages:
    626
    Likes Received:
    129
    Trophy Points:
    810
    Location:
    Russian Federation
    Last edited: Aug 26, 2016
  3. Homam Alkurdy

    Homam Alkurdy Active Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Hamburg
    Thank you for your help i just wrote this code and its work
    Code (SQL):

    DROP TABLE T1 ;
    DROP SEQUENCE T1_SEQUENCE;

    CREATE TABLE T1
    (
        NUM NUMBER ,
        VAL NUMBER  
    );
    CREATE SEQUENCE T1_SEQUENCE
      MINVALUE 0
      START WITH 1
      INCREMENT BY 1;
    CREATE OR REPLACE TRIGGER T1_ON_INSERT
      BEFORE INSERT ON T1
      FOR EACH ROW
    BEGIN
      SELECT T1_SEQUENCE.NEXTVAL
      INTO :NEW.NUM
      FROM DUAL
     
      ;
      END;
    INSERT INTO T1(VAL)
      SELECT (DBMS_RANDOM.VALUE(1,LEVEL))
       FROM DUAL  
       CONNECT BY LEVEL <= 100
       ORDER BY(DBMS_RANDOM.VALUE(1,LEVEL));
    SELECT * FROM T1
    ORDER BY NUM
    ;
    Now if you can help me i have to write a script and the results should be like
    Num 1 is the 1.smallest value
    .
    .
    .
    .
    .
    Num 100 is the biggest value
    Thank you for your help
    Homam
     
  4. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,347
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You have an example so use it and modify it to meet your needs. It isn't our job to do your homework.
     
  5. Homam Alkurdy

    Homam Alkurdy Active Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Hamburg
    By the way im learning by myself on the internet and its not a homework and there is no one helping me this is a case study i found it in the internet thank you for this great words and for your help but i think if you dont want help you dont have to write any things its better try to save your effort for something useful for another one
     
  6. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,347
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    The code you wrote looks more like it was copied from another website as it's far more complex than a simple beginner would write. That being the case the select statement you have can be slightly modified (remove the second column) to return the data values. Adding the text, the easiest way, would be :

    Code (SQL):
    SELECT num,
        CASE WHEN num = 1 THEN ' is the lowest value'
             WHEN num BETWEEN 2 AND 50 THEN ' is the next lowest value'
             WHEN num BETWEEN 51 AND 99 THEN ' is the next highest value'
             WHEN num = 100 THEN ' is the highest value' END
    FROM t1;
     
    It would help you tremendously if you would learn from the examples of others by figuring out how they work; another item you need to address is reading the Oracle on-line documentation so you can learn things on your own.

    You can't expect everyone to write your queries every time you want one.
     
  7. Sadik

    Sadik Community Moderator Forum Guru

    Messages:
    1,906
    Likes Received:
    252
    Trophy Points:
    1,455
    I have learnt more than one programming languages by getting my hand dirty... I have written the "absurdest" of codes because I had no idea what I was doing when I began learning php... But the errors help you to learn more than just reading theory in my opinion.

    That said @Homam Alkurdy you are doing very well, if the above was the code you wrote and welcome to club-oracle! :)