0

I need the procedure to give me the next solution: I will add two tables from another place into my tables (done), then I write a procedure to add a new value to the third table, that will be the first table + the second table. I have a problem when I execute the tables, maybe I'm doing something wrong and I would be glad if you could help me.

Also, I don't know how to use "cursor is" but if you could help me of an example with this, that would be awesome.

Sorry for my bad English, I'm trying to learn it just to be part of this community :)

I created the tab_ejercicio with three tables

create table tab_ejercicio
(FirstName, varchar2(45),Address, varchar2(45),Thing varchar2(100));

Then I bring the other tables into the first two tables of ejercicio

INSERT INTO tab_ejercicio (FirstName, Address)
SELECT T3.STREET_ADDRESS,t2.first_name
FROM   HR.DEPARTMENTS t1,
       HR.EMPLOYEES   t2,
       HR.LOCATIONS   t3
WHERE  T1.department_id = t2.DEPARTMENT_ID
AND    t1.LOCATION_ID   = t3.LOCATION_ID

and now the procedure

CREATE OR REPLACE PROCEDURE PRC_PALABRALONGITUD2(Palabra varchar2, palabra2 varchar2)
IS
NewWord varchar2(100);
Length number(8);
w number(1);
begin
Length:=len(Word);
w:=mod(Length,2);
if w = 0 then 
        NewWord:= Word2 || Word;
else
        NewWord:= Word|| Word2;
end if;
insert 
into tab_ejercicio (Thing)
values (NewWord);
end;

I have problems here, since I don't know how to do it well, but I thought it would be something like this, adding the tables I want to use in the procedure

execute PRC_PALABRALONGITUD2(FirstName,Address);

And finally lets print the tab so we can see I fail :(

select *
from tab_ejercicio;
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Please define your RDBMS in tags. – Bartosz Siemasz Oct 17 '18 at 16:56
  • @BartoszSiemasz i don´t know what's a RBDMS :( – Henry Aranda Oct 17 '18 at 17:26
  • RDBMS = Relational Database Management System - it means you should tell us **what concrete database** you're using - Oracle? PostgreSQL? SQL Server? MySQL? Something else?? Please add a relevant tag ! – marc_s Oct 17 '18 at 17:52
  • 1
    [Bad habits to kick : using old-style JOINs](https://sqlblog.org/2009/10/08/bad-habits-to-kick-using-old-style-joins) - that old-style *comma-separated list of tables* style was replaced with the *proper* ANSI `JOIN` syntax in the ANSI-**92** SQL Standard (**more than 25 years** ago) and its use is discouraged – marc_s Oct 17 '18 at 17:52
  • 2
    Then your teacher needs to upgrade his knowledge - **urgently!** – marc_s Oct 17 '18 at 18:01
  • @marc_s it is SQL, we use oracle sql developer and vmware workstation – Henry Aranda Oct 17 '18 at 18:01
  • @marc_s jaja we are from a third world country, it would be hard to make him change his ways – Henry Aranda Oct 17 '18 at 18:02
  • Another bad habit to kick is [Hungarian notation](https://stackoverflow.com/a/202135/2799848) (putting `tab_` and `prc_` in your object names) – Elaskanator Oct 17 '18 at 18:40
  • i will try to avoid them, while searching a way for the code to work – Henry Aranda Oct 18 '18 at 15:19

0 Answers0