Inserting multiple rows in sqlplus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raj Kotaru

    Inserting multiple rows in sqlplus

    Hi,

    In sqlplus, I can insert a single row using:

    insert into employee
    (name, salary, hiredate)
    values
    ('xyz', '86378', sysdate);

    Is there a modification of the insert command that will allow me to
    insert more than one row into a table without having to resort to
    multiple "insert into ..." statements?

    For example, can I insert two rows via something that lloks like:

    insert into employee
    (name, salary, hiredate)
    values
    {
    ('xyz', '86378', sysdate),
    ('abc', '84249', sysdate-1)
    };

    Here I am assuming that { } encloses all valid rows, with () enclosing
    a single row within the surrounding {}.


    I do not want to use the sql loader, PL-SQL, or SQL-PLUS constructs
    like functions, scripts, and stored procedures.

    Thanks
    Raj
  • Bricklen

    #2
    Re: Inserting multiple rows in sqlplus

    Raj Kotaru wrote:
    I do not want to use the sql loader, PL-SQL, or SQL-PLUS constructs
    like functions, scripts, and stored procedures.
    well, you're SOL then

    Comment

    • Ana C. Dent

      #3
      Re: Inserting multiple rows in sqlplus

      Raj Kotaru wrote:
      Hi,
      >
      In sqlplus, I can insert a single row using:
      >
      insert into employee
      (name, salary, hiredate)
      values
      ('xyz', '86378', sysdate);
      >
      Is there a modification of the insert command that will allow me to
      insert more than one row into a table without having to resort to
      multiple "insert into ..." statements?
      >
      For example, can I insert two rows via something that lloks like:
      >
      insert into employee
      (name, salary, hiredate)
      values
      {
      ('xyz', '86378', sysdate),
      ('abc', '84249', sysdate-1)
      };
      >
      Here I am assuming that { } encloses all valid rows, with () enclosing
      a single row within the surrounding {}.
      >
      >
      I do not want to use the sql loader, PL-SQL, or SQL-PLUS constructs
      like functions, scripts, and stored procedures.
      >
      Thanks
      Raj
      INSERT INTO EMPLOYEE AS
      SELECT A.NAME, B.SALARY, C.HIREDATE
      FROM NAME_TABLE A, SALARY_TABLE B, HIREDATE_TABLE C
      WHERE A.SSN = B.SSN
      AND A.SSN = C.SSN;

      Comment

      • Jim Kennedy

        #4
        Re: Inserting multiple rows in sqlplus


        "Raj Kotaru" <raj_kotaru@hot mail.comwrote in message
        news:67bf894f.0 401221322.33dd1 4e3@posting.goo gle.com...
        Hi,
        >
        In sqlplus, I can insert a single row using:
        >
        insert into employee
        (name, salary, hiredate)
        values
        ('xyz', '86378', sysdate);
        >
        Is there a modification of the insert command that will allow me to
        insert more than one row into a table without having to resort to
        multiple "insert into ..." statements?
        >
        For example, can I insert two rows via something that lloks like:
        >
        insert into employee
        (name, salary, hiredate)
        values
        {
        ('xyz', '86378', sysdate),
        ('abc', '84249', sysdate-1)
        };
        >
        Here I am assuming that { } encloses all valid rows, with () enclosing
        a single row within the surrounding {}.
        >
        >
        I do not want to use the sql loader, PL-SQL, or SQL-PLUS constructs
        like functions, scripts, and stored procedures.
        >
        Thanks
        Raj
        Not really. But you could create an external table (if you are using 9i)
        and then do a select into.
        Is this for school? SQLLoader does this by multiple insert statements and
        bind variables.
        Jim


        Comment

        • Hans Forbrich

          #5
          Re: Inserting multiple rows in sqlplus

          Raj Kotaru wrote:
          >
          Hi,
          >
          In sqlplus, I can insert a single row using:
          >
          insert into employee
          (name, salary, hiredate)
          values
          ('xyz', '86378', sysdate);
          >
          Is there a modification of the insert command that will allow me to
          insert more than one row into a table without having to resort to
          multiple "insert into ..." statements?
          >
          For example, can I insert two rows via something that lloks like:
          >
          insert into employee
          (name, salary, hiredate)
          values
          {
          ('xyz', '86378', sysdate),
          ('abc', '84249', sysdate-1)
          };
          >
          Here I am assuming that { } encloses all valid rows, with () enclosing
          a single row within the surrounding {}.
          >
          I do not want to use the sql loader, PL-SQL, or SQL-PLUS constructs
          like functions, scripts, and stored procedures.
          >
          Thanks
          Raj
          Oracle does not support what you ask, and AFAIk neither does the SQL
          standard. (Corrections appreciated if I'm wrong here.)

          I'm not sure why *you* want this, although I can think of several
          reasons. Nor do I know your environmnt, your Oracle version, your
          operating system version, or your data source. I'd certianly be
          interested in the reasoning behind your restrictions about SQL Loader,
          etc.

          Some alternate ways I've used to do something like this:

          1) With a flat file and Oracle9i, consider External Tables;
          2) If data is in the database already, use CTAS;
          3) Create a SQL Plus script to contains all inserts. If possible
          (incredibly easy in unix/linux), generate the script using sed, awk or
          perl. Cut size by inserting against a view that maps only to the
          columns you want, eliminating the column spec.

          <rant>
          While there may be legit reasons for the restrictions, you are
          effectively increasing the cost of your Oracle investment. This is
          similar to saying "though shalt not use the power seats, power windows
          or radio in the car - the money that was spent on those features is
          wasted."
          </rant>

          Comment

          Working...