r/plsql • • Feb 14 '19

Help with a query to get data minute by minute?

2 Upvotes

Hi all, I am trying to build a query that will look back at our login audit table and I am trying to find the maximum number of logins per minute, looking back at the last two weeks worth of data.

This will be used to find which individual minute in the last two weeks had the highest number of logins.

So far I have something like this:

SELECT COUNT (*), sysdate - 1/24/60
  FROM AUDIT_TABLE
WHERE AUDIT_TIME > SYSDATE - 1/24/60;

And this is getting the count of login records for the last minute, but I want to go over many days of data, minute by minute.

Any ideas?


r/plsql • • Oct 01 '18

Newbie - Oracle SQL Developer - best free tool for running SQL commands?

2 Upvotes

Hello.

I'm a complete non-expert in SQL and Oracle tech. I'm using SQL Developer along with my company colleagues, to manage connections to multiple Oracle DBs and run queries. The performance of this program seems .... sluggish.

Just checking if anyone thinks there any better programs for managing oracle DB connections and running queries than the free SQL Developer?


r/plsql • • Jun 20 '18

Handling PL/SQL Errors

Thumbnail
oracledbcentral.blogspot.com
2 Upvotes

r/plsql • • May 29 '18

use of cursors

2 Upvotes

Hello, So I'm pretty new to PL/SQL... Here is what I need to do: I need to return the list of a query using the CATSEARCH index. I created a little table populated with 5 rows.

The table looks like this:

CREATE TABLE produits ("NUM_ID" NUMBER, 
	"TITRE" VARCHAR2(100 BYTE), 
	"DESCRIPTION" VARCHAR2(100 BYTE), 
	"CATEGORIE" VARCHAR2(100 BYTE), 
	"PRIX" NUMBER)

One example of a row is "1", "Pull bleu", "Joli pullhomme", "Habits", "100" (sorry, it is in French, it is only a description of a cloth in that table).

I created a CATSEARCH index, and I am actually able to use it to search. For example, the query

select * from produits
WHERE CATSEARCH(titre, 'pull', 'order by prix')> 0;

returns the 2 following rows of my table:

"1", "Pull bleu", "Joli pull homme", "Habits", "100" "2", "Pull rouge", "Joli pull doré", "Habits", "250"

So it found all the rows with "Pull" in it. It is working. Now, I'm stuck because I need to create a package (that I will later call from APEX) that contains this CATSEARCH query. I created a PROCEDURE with a CURSOR to make this search, but I can't find a way to make it work... Here is what my procedure looks like:

create or replace PROCEDURE rechercher (p_terme VARCHAR2) 
IS
resultat VARCHAR2(100);
CURSOR cni IS   SELECT titre,
                        description,
                        categorie,
                        prix
                FROM produits;
 
 BEGIN
FOR vc IN cni LOOP
SELECT titre
    INTO resultat
    FROM produits
   WHERE CATSEARCH(titre, 'p_terme', 'order by prix')> 0;
  END LOOP ;
END rechercher;

And I'm calling it using...

SET SERVEROUTPUT ON
begin
rechercher('pull');
end;

The error says: 01403. 00000 - "no data found" *Cause: No data was found from the objects. *Action: There was no data from the objects which may be due to end of fetch.

I tried a lot of different ways, I can't make it work... I'd really like some help on this :-/ Thanks a lot for reading


r/plsql • • May 02 '18

Required Skills for the Job of SQL Developer / PL/SQL Developer

2 Upvotes

I have been learning Oracle SQL and PL/SQL for almost a year now, and have decided that I would like to pursue a career as a SQL Developer or a PL/SQL Developer.

What skills are required to be a suitable candidate for a job as a developer? Are there any great resources for what skills are required for the job? Finally, what resources are available to learn these skills, if I need to brush up on them or introduce myself to them?


r/plsql • • Mar 24 '18

help with code

2 Upvotes

that's my code:

create or replace procedure popula_professor_turma ( oi in char) is vlinha professor.numero_funcional%type := 0; vturma integer :=0; vturmaprof integer :=0; cursor vdiscip is select id_discip from disciplina; begin FOR i IN vdiscip LOOP vlinha := 0; vturma := 0; select mod(round(DBMS_RANDOM.VALUE (0, 450), 0), 150) + 1 into vlinha from dual; select turma from professor into vturma where colunalegal = vlinha; while vturma = 1 loop if vlinha=150 then vlinha := 0; end if; vlinha := vlinha+1; select turma from professor into vturmaprof where colunalegal = vlinha; if vturmaprof = 0 then exit; end if; end loop; update turma set num_funcional = vlinha where id_discip = i.id_discip; update professor set turma = 1 where colunalegal = vlinha; END LOOP; end;

and isn't working, i'm getting troubles with lines 12 and 18

LINE/COL ERROR


12/1 PL/SQL: SQL Statement ignored 12/29 PL/SQL: ORA-00933: comando SQL nÒo encerrado adequadamente 18/1 PL/SQL: SQL Statement ignored 18/29 PL/SQL: ORA-00933: comando SQL nÒo encerrado adequadamente

i really didnt get what am i doing wrong

those are the tables descriptions:

Nome Nulo? Tipo


NUMERO_FUNCIONAL NOT NULL NUMBER(38) NOME_PROFESSOR NOT NULL VARCHAR2(50) CEP_PROFESSOR VARCHAR2(8) SEXO_PROFESSOR NOT NULL CHAR(1) DT_NASC_PROF DATE DT_ADMISS_PROF DATE TITULACAO VARCHAR2(10) ID_TURMA NUMBER(38) END_NUMERO NUMBER(38) END_COMPLEMENTO VARCHAR2(20) TURMA NUMBER(38) COLUNALEGAL NUMBER(38)

Nome Nulo? Tipo


ID_TURMA NOT NULL CHAR(8) TURNO NOT NULL CHAR(1) PERIODO NOT NULL NUMBER(38) ID_DISCIP CHAR(6) NUM_FUNCIONAL NUMBER(38)


r/plsql • • Nov 29 '17

Oracle SQL INTERSECT Set Operator

Thumbnail
oraappdata.com
2 Upvotes

r/plsql • • Nov 27 '17

Oracle SQL UNION ALL Set Operator

Thumbnail
oraappdata.com
2 Upvotes

r/plsql • • Nov 13 '17

SQL position output question

2 Upvotes

Hello,

So i'm trying to get a nice output( the below image is just a test-table with random input but you will get the picture anyways ). https://imgur.com/a/ZfQDW

So as you can see in the bottom row the second column starts a few whitespaces further to the right than the first row.

Can I somehow hardcore/set on which position the output from the second column shall start?

Thanks in advance


r/plsql • • Oct 26 '17

Need Some Help!!

2 Upvotes

These past few weeks I've been trying to teach myself some PL/SQL Oracle database. It hard because I jump around from different tutorial programs from UDemy to Datacamp. I really want to start studying for the Oracle Database 11g: SQL Fundamentals I exam. Need some direction please.


r/plsql • • Oct 20 '17

Replication from Oracle to SQL Server, without extra configuration to Oracle. Possible?

2 Upvotes

I've got a very large remote Oracle database (10's of billions of records) that needs to be replicated to a local SQL server for our analysts to look at. We have login/read access to the server, but we can't update anything on the oracle side.

Is it still possible to setup SQL Server to replicate (extract) oracle's data? =)

Thanks!


r/plsql • • Oct 10 '17

This app takes users input plsql file (package, procedures script) and publishes Insights on source code with visual charts and in tabular format.

Thumbnail
play.google.com
2 Upvotes

r/plsql • • Sep 25 '17

Precision of 0, when column datatype is NUMBER.

2 Upvotes

I am trying to create a patch that alters the datatype of columns that were defined as NUMBER to have some precision and scale like NUMBER(p,s). I am getting an error when I run my patch on my test schema, ORA-01440 "column to be modified must be empty to decrease precision or scale".

All the values in the column that this refers to are 0 and I am trying to change the datatype to NUMBER(20,2). From my understanding, if number columns do not have a defined precision or scale then the precision and scale is based on the values stored in the column.

Why would values of zero have a precision greater that 20?


r/plsql • • May 11 '17

Receiving a ORA-01722 "invalid number" error

2 Upvotes

Howdy, /r plsql I'm receiving an invalid number error when utilizing a max() return on a datatype that is set for date. TOAD has indicated that the error is coming from the max(trandate) calls. I'm also attaching the code:

select getpik(a.PATRONID) || ',' || c.lastname || ',' || c.firstname || ',' ||'$'|| a.balance/100 || ',' || max(b.TRANDATE) from patronsvcplans a, generalledg_v b, patron_flat_view c where a.patronid = b.patronid and b.patronid = c.patronid and a.planid = 69 and b.ACCOUNTNUMBER = 69 and a.balance > 0 and c.magstripe is not null group by a.patronid, a.balance/100, c.lastname, c.firstname having max(b.trandate) <sysdate - 1825 order by max(b.trandate);

Thanks! -Sheep


r/plsql • • May 07 '17

anybody has tried UTL_MAIL package on oracle? I cant send mail.. it always gives me error

2 Upvotes

hey guys there is a utl_mail (inbuilt package) in oracle. It has inbuilt procedure 'send' which sends email to whichever Id I want. I have been trying to send email using 'UTL_MAIL' package in oracle on my home desktop. I have tried everything but I just cant send email through utl_mail.send procedure. can anybody tell me what could be going wrong?


r/plsql • • May 05 '17

Querying and sorting a big table in Oracle 12c

2 Upvotes

Can somebody please point me in the right direction regarding DB architecture. I am building a classifieds type website. An object has several parameters and description. I want to implement fast search by parameters and description and few types of sorting - by submission date, price, type etc. I have millions of records.

I submitted a simplified description here http://stackoverflow.com/questions/43797774/querying-and-sorting-a-big-table-in-oracle-12c

I am using several pre sorted materialized views and it works OK, but refreshing is a pain. I tried descending indexes but it doesn't help.

Thanks


r/plsql • • Apr 15 '17

PL/SQL syntax checker

2 Upvotes

Is there product or tool or add-on to an editor that will highlight syntax ERRORS in PL/SQL.

Obviously, it would have no way of knowing if a table or column name is correct or data really exists. But other than that, is there something that can highlight syntax errors in PL/SQL like Visual Studio does for C++ or PyCharm does for Python?


r/plsql • • Apr 09 '17

Need Help With Oracle SQL

2 Upvotes

When I try to run this on oracle this error keeps popping up. Does anyone know what is wrong with the coding? ORA-01747: invalid user.table.column, table.column, or column specification

CREATE TABLE CUSTOMER (
    NAME VARCHAR2(20),
    ORDER_ID INT PRIMARY KEY,
    DATE DATE);

INSERT INTO CUSTOMER(NAME, ORDER_ID, DATE) 
VALUES('Joe', 1, '1-APR-17');

r/plsql • • Apr 05 '17

Can anybody help me with ER modelling for library database?

2 Upvotes

Hey guys, I am doing project on ER modelling. I am new to DBMS.. though I have tried my best to do ER modelling process on library entities and attributes. can anybody check and tell me if I am doing correct, or if not where am I going wrong.

please message me your email ID.. I really would like to have a professional guidance.. thank you..


r/plsql • • Mar 27 '17

Doubt: Cardinality and relation while making table

2 Upvotes

hey guys.. I have been studying normalization and was designing sample database for library. I have one question on this scenario:

I have created table TRANSACTIONS (borrow + return of books). it has following columns: Transaction_id (primary key) Date of issuance: Date of return: Member_id (foreign key) Book_serial_no:(foreign key) Magazine_serial_no:(foreign key) Newspaper_serail_no:(foreign key)

I was learning DBMS and concept of entities relations etc. as far as this table is concerned "Transactions" don't seem to be an entity, rather it seems to be a relation. lets say, member - transacts - book/magazine/newspaper. so my first question is, is there any rule that tables can only be made from entities? or is it allowed to make table for relation as well?


r/plsql • • Mar 17 '17

Can anybody give me basic example of how to create scripts in SQL?

2 Upvotes

I was trying to see how @ and @@ works in SQL*plus and i found it on internet that it is used for http links. but i cant really understand how that is done. and why that has to be done. DO we use it to insert hyperlinks in a table or do we embed sql command in hyperlink.

any basic example on any general schema using @ and @@ will help me understand. thank you :* :*


r/plsql • • Mar 11 '17

why this "instead of" trigger does not work?

2 Upvotes

Instead of trigger is created specifically on views. so far I have created few triggers on views belong to user HR in SYS (including instead of)

however this one doesn't work (this one is created in SYS as SYSDBA user)

create or replace trigger view_trigger
    Instead of dml on hr.exp_view
begin
    insert into ddl_audit
    values
(DDL_SEQ.NEXTVAL, ORA_SYSEVENT, USER, SYSTIMESTAMP, ORA_DICT_OBJ_TYPE, 
     ORA_DICT_OBJ_NAME, ORA_DICT_OBJ_OWNER);
END;

this is the error it throws: Instead of ddl on exp_view * ERROR at line 2: ORA-30513: cannot create system triggers of INSTEAD OF type

if that is the case then why my other (instead of) triggers on views got created in the first place.


r/plsql • • Mar 04 '17

Why exception doesn't work inside loop?

2 Upvotes

hey guys I tried to run a small PLSQL procedure where in I have loop for multiple outputs and within which I am trying to raise an exception. but no matter what it doesn't work.. loop stops as soon as exception is raised. there is no content given on this in Oracle books or to that matter even on internet.


r/plsql • • Feb 01 '17

How would I do an ISO Week number based on Friday for the week start (Fri - Thurs)?

2 Upvotes

I'm trying to do some productivity stats based on our application's database.

However we value a week starting on Friday and ending on Thursday.

Ideally I want to use ISO Week Number "YY-IW" to sort aggregated data, but this is monday based.

Excel allows for WEEKNUM where you pass variable into it to tell it the starting day (monday vs friday)

Any ideas on how to do that easily?

Act being 'Action'

to_char(trunc( GP_ACT_DATE),'IY-IW') ACT_WEEK

Edit: Well I convinced the laboratory to start using an ISO week so dont even need to worry about this nonsense anymore. :)


r/plsql • • Jan 18 '17

The right way to use put_line() in plsql?

2 Upvotes

I'm self taught with plsql, and I have a number of dbms_output.put_line() statements sprinkled throughout a procedure and some functions for debugging. Usually, my functions are just logic/transformations applied to each rows column value, but occasionally we have bad data and when I hit these values I like to catch the exception, print it out, put a null placeholder in and move on. I use these procedures and functions in many applications, sometimes in simple select statements, sometimes when creating tables, and sometimes in other procedures/functions.

I've noticed that my put_line statements don't get printed in my dbms_output window. I think this is because I just don't understand what is going on though, particularly with the buffer. What I've come to do is have a dummy function that I compile after calling one of these which (I assume) flushes the buffer and outputs it all into my window where I can now see it. I notice I don't need to do that when I print in an anonymous block though, which tells me I'm not doing this right.

I'm reading here where their example shows a declaration of a "line" object and also a line count. Then they put the lines, get the lines, and then put the lines again, except this time putting the line object rather than the character string.

This seems ridiculous to me - does that mean when I use put_line in a compiled plsql block that I need to also always declare a line object and keep a running count every time a line is put. Then afterwards I have to loop over the buffer and put them again?

Or am I misunderstanding something? Just for the record, I have dbms_output enabled, I'm in SQLDeveloper 4.1, my dbms_output window is open and linked to the right connection. I can get output, but not without that dummy compiling.

Could anyone help me figure out what I don't understand? Thanks!